28 lines
629 B
TypeScript
28 lines
629 B
TypeScript
function getCookieMap() {
|
|
const cookies = document.cookie.split('; ');
|
|
const cookieMap = new Map<string, string>();
|
|
for (let i = 0; i < cookies.length; i++) {
|
|
const cookie = cookies[i];
|
|
if (!cookie) continue;
|
|
let [key, value] = cookie.split('=');
|
|
if (!key || !value) continue;
|
|
cookieMap.set(key, value);
|
|
}
|
|
|
|
return cookieMap;
|
|
}
|
|
|
|
class UserState {
|
|
isLoggedIn = $state(false);
|
|
|
|
constructor() {
|
|
this.checkIsLoggedIn();
|
|
}
|
|
|
|
checkIsLoggedIn() {
|
|
const cookieVal = getCookieMap().get('pt-auth');
|
|
this.isLoggedIn = cookieVal !== undefined;
|
|
}
|
|
}
|
|
|
|
export const userstate = new UserState();
|