This commit is contained in:
@@ -2,7 +2,7 @@ import type { providerType, UserState } from './types';
|
||||
import type { LoginReq } from '@/api/user/types';
|
||||
import { defineStore } from 'pinia';
|
||||
import { UserApi } from '@/api';
|
||||
import { refreshToken } from '@/api/auth';
|
||||
import { refreshToken, type UserInfo } from '@/api/auth';
|
||||
|
||||
import { clearToken, setToken } from '@/utils/auth';
|
||||
|
||||
@@ -82,12 +82,22 @@ const useUserStore = defineStore('user', {
|
||||
|
||||
try {
|
||||
const res = await refreshToken(refresh_token);
|
||||
const rawUserInfo = uni.getStorageSync('user_info');
|
||||
const cachedUserInfo = rawUserInfo && typeof rawUserInfo === 'object'
|
||||
? rawUserInfo as Partial<UserInfo>
|
||||
: {};
|
||||
const cachedButtons = Array.isArray(cachedUserInfo.buttons) ? cachedUserInfo.buttons : [];
|
||||
const sessionUser = {
|
||||
...cachedUserInfo,
|
||||
...res.user,
|
||||
buttons: Array.isArray(res.buttons) ? res.buttons : cachedButtons,
|
||||
};
|
||||
// 更新 access_token
|
||||
setToken(res.access_token);
|
||||
// 更新 refresh_token
|
||||
uni.setStorageSync('refresh_token', res.refresh_token);
|
||||
// 更新用户信息
|
||||
uni.setStorageSync('user_info', res.user);
|
||||
uni.setStorageSync('user_info', sessionUser);
|
||||
return res;
|
||||
}
|
||||
catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user