添加从根路径到/app/dashboard的服务器端重定向 创建包含主内容容器的应用布局组件 实现带响应式侧边栏和顶栏的仪表盘页面 添加带平滑过渡效果的侧边栏切换功能 设置基础用户状态管理仓库 使用对等依赖标志更新package-lock.json中的依赖项 从锁定文件中移除冗余的picomatch条目 添加带路径解析导入的登录页面组件
38 lines
874 B
TypeScript
38 lines
874 B
TypeScript
import {writable} from 'svelte/store';
|
|
import { browser } from '$app/environment';
|
|
|
|
export interface AuthStore {
|
|
token: string | null;
|
|
tokenHead: string | null;
|
|
isAuthenticated: boolean;
|
|
}
|
|
|
|
let initialToken: string | null = null;
|
|
let initialTokenHead: string | null = null;
|
|
|
|
|
|
if (browser) {
|
|
initialToken = localStorage.getItem('auth_token');
|
|
initialTokenHead = localStorage.getItem('auth_token_head');
|
|
}
|
|
|
|
const initialAuthStore: AuthStore = {
|
|
token: initialToken,
|
|
tokenHead: initialTokenHead,
|
|
isAuthenticated: initialToken !== null
|
|
}
|
|
|
|
const authStatusStore = writable<AuthStore>({
|
|
token: initialToken,
|
|
tokenHead: initialTokenHead,
|
|
isAuthenticated: initialToken !== null
|
|
})
|
|
|
|
export const authStore = {
|
|
subscribe: authStatusStore.subscribe,
|
|
set: authStatusStore.set,
|
|
update: authStatusStore.update,
|
|
clear: () => {
|
|
authStatusStore.set(initialAuthStore);
|
|
},
|
|
}; |