解决登录显示、首页显示bug
This commit is contained in:
@@ -49,6 +49,27 @@ export const setUserProfile = (profile : UserProfile) => {
|
||||
state.userProfile = profile
|
||||
}
|
||||
|
||||
function clearUserAuthStorage() : void {
|
||||
const keys : Array<string> = [
|
||||
'userInfo',
|
||||
'user_id',
|
||||
'access_token',
|
||||
'refresh_token',
|
||||
'token',
|
||||
'currentUser',
|
||||
'current_user',
|
||||
'user',
|
||||
'auth_user',
|
||||
'supabase.auth.token'
|
||||
]
|
||||
|
||||
for (let i = 0; i < keys.length; i++) {
|
||||
try {
|
||||
uni.removeStorageSync(keys[i])
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
|
||||
// 获取当前用户信息(含补全 profile)
|
||||
export async function getCurrentUser() : Promise<UserProfile | null> {
|
||||
try {
|
||||
@@ -191,6 +212,8 @@ export async function getCurrentUser() : Promise<UserProfile | null> {
|
||||
// 登出并清空用户信息
|
||||
export function logout() {
|
||||
supa.signOut()
|
||||
clearUserAuthStorage()
|
||||
state.authUser = null
|
||||
state.userProfile = { username: '', email: '' } as UserProfile
|
||||
state.isLoggedIn = false // 登出
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user