Showing
1 changed file
with
8 additions
and
2 deletions
| 1 | /* | 1 | /* |
| 2 | * @Date: 2025-03-20 21:11:31 | 2 | * @Date: 2025-03-20 21:11:31 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2025-06-15 20:06:25 | 4 | + * @LastEditTime: 2025-07-07 11:27:17 |
| 5 | * @FilePath: /mlaj/src/contexts/auth.js | 5 | * @FilePath: /mlaj/src/contexts/auth.js |
| 6 | * @Description: 认证上下文管理模块,提供用户认证状态管理、登录登出功能 | 6 | * @Description: 认证上下文管理模块,提供用户认证状态管理、登录登出功能 |
| 7 | */ | 7 | */ |
| ... | @@ -71,13 +71,19 @@ export function provideAuth() { | ... | @@ -71,13 +71,19 @@ export function provideAuth() { |
| 71 | logout() | 71 | logout() |
| 72 | } | 72 | } |
| 73 | } else { | 73 | } else { |
| 74 | - // 查询用户是否授权, 从服务器获取用户信息并更新本地存储 | ||
| 75 | const { code, data } = await getAuthInfoAPI(); | 74 | const { code, data } = await getAuthInfoAPI(); |
| 76 | if(code) { | 75 | if(code) { |
| 76 | + // 查询用户是否授权, 从服务器获取用户信息并更新本地存储 | ||
| 77 | if (data.openid_has) { | 77 | if (data.openid_has) { |
| 78 | currentUser.value = { ...data.user, ...data.checkin } | 78 | currentUser.value = { ...data.user, ...data.checkin } |
| 79 | localStorage.setItem('currentUser', JSON.stringify(currentUser.value)) | 79 | localStorage.setItem('currentUser', JSON.stringify(currentUser.value)) |
| 80 | } | 80 | } |
| 81 | + // 判断用户是否已经登录 | ||
| 82 | + if (data?.user?.id) { | ||
| 83 | + // 已登录,更新用户状态 | ||
| 84 | + currentUser.value = { ...data.user, ...data.checkin } | ||
| 85 | + localStorage.setItem('currentUser', JSON.stringify(currentUser.value)) | ||
| 86 | + } | ||
| 81 | } | 87 | } |
| 82 | } | 88 | } |
| 83 | // 初始化完成,关闭加载状态 | 89 | // 初始化完成,关闭加载状态 | ... | ... |
-
Please register or login to post a comment