提交
This commit is contained in:
1 parent
80138c6388
commit
693e8a678e
682 files changed
+211375
-5306
No files matched your search
+29
-1
@@ -1,6 +1,6 @@
|
||||
import { validateCredentials } from './validate-credentials.js'
|
||||
import { buildEncryptedLoginBody } from './login-rsa.js'
|
||||
import { post } from './request.js'
|
||||
import { get, post } from './request.js'
|
||||
|
||||
export { validateCredentials }
|
||||
|
||||
@@ -53,6 +53,34 @@ function saveSession({ token, refreshToken, userInfo }) {
|
||||
uni.setStorageSync(USER_KEY, JSON.stringify(userInfo || null))
|
||||
}
|
||||
|
||||
/** 更新本地缓存的用户信息(保留 token)。 */
|
||||
export function updateStoredUser(userInfo) {
|
||||
try {
|
||||
uni.setStorageSync(USER_KEY, JSON.stringify(userInfo || null))
|
||||
} catch (e) {
|
||||
/* ignore */
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 拉取当前用户资料并写回本地(含职位、部门)。
|
||||
* @returns {Promise<object|null>}
|
||||
*/
|
||||
export async function fetchCurrentUser() {
|
||||
const token = getToken()
|
||||
if (!token) return null
|
||||
const data = await get('/web/auth/current-user', {
|
||||
Authorization: 'Bearer ' + token
|
||||
})
|
||||
if (data) {
|
||||
const prev = getUser() || {}
|
||||
const merged = Object.assign({}, prev, data)
|
||||
updateStoredUser(merged)
|
||||
return merged
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* 可选:清除历史 mock_ 前缀假会话,避免误判已登录。
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user