feat(auth): 实现基于令牌的用户认证和访问控制
- 在用户相关页面服务端加载函数中添加令牌检查,防止未授权访问 - 更新用户服务方法以支持携带认证令牌请求API - 修改用户资料和用户列表组件以适配新的认证流程 - 引入侧边栏状态管理并在布局中注册上下文 - 调整HTTP客户端逻辑以正确传递请求头信息 - 更新用户类型定义以匹配后端返回的角色结构 - 优化应用头部和侧边栏组件的UI细节和交互逻辑
This commit is contained in:
16
src/routes/app/user/+page.server.ts
Normal file
16
src/routes/app/user/+page.server.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { COOKIE_TOKEN_KEY } from '$lib/components/constants/cookiesConstants.ts';
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
import { userService } from '$lib/api/services/userService.ts';
|
||||
|
||||
export async function load({cookies}) {
|
||||
const token = cookies.get(COOKIE_TOKEN_KEY);
|
||||
if (!token) {
|
||||
throw redirect(302, '/auth/login');
|
||||
}
|
||||
|
||||
const profile = await userService.getUserProfile(token);
|
||||
|
||||
return {
|
||||
profile
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user