15 lines
424 B
TypeScript
15 lines
424 B
TypeScript
import { userState } from '$lib/shared.svelte';
|
|
|
|
export const getCookieValue = (name: String) =>
|
|
document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]+)')?.pop() || '';
|
|
|
|
export function updateUserState() {
|
|
const JWT = getCookieValue('jwt');
|
|
if (JWT !== '') {
|
|
const state = JSON.parse(atob(JWT.split('.')[1]));
|
|
userState.perms = state.perms;
|
|
userState.username = state.username;
|
|
userState.id = state.id;
|
|
}
|
|
}
|