diff --git a/frontend/src/api/pocketbase.ts b/frontend/src/api/pocketbase.ts index 982889a..250b006 100644 --- a/frontend/src/api/pocketbase.ts +++ b/frontend/src/api/pocketbase.ts @@ -5,13 +5,7 @@ const pbUrl = import.meta.env.VITE_PB_URL || window.location.origin export const pb = new PocketBase(pbUrl) -// 认证状态持久化 -pb.authStore.loadFromCookie(document.cookie) - -// 保存认证状态到 cookie -pb.authStore.onChange(() => { - document.cookie = pb.authStore.exportToCookie({ httpOnly: false, path: '/' }) -}) +// SDK v0.21+ 自动使用 localStorage 持久化,无需手动 cookie 操作 // 获取当前用户 export function getCurrentUser() { diff --git a/frontend/src/stores/user.ts b/frontend/src/stores/user.ts index f2fc598..18518ee 100644 --- a/frontend/src/stores/user.ts +++ b/frontend/src/stores/user.ts @@ -12,7 +12,7 @@ export const useUserStore = defineStore('user', () => { // 计算属性 const isLoggedIn = computed(() => isAuthenticated() && user.value !== null) - const userStatus = computed(() => user.value?.status || 'away') + const userStatus = computed(() => user.value?.status || 'idle') const userId = computed(() => user.value?.id || '') // 初始化用户信息 @@ -41,6 +41,10 @@ export const useUserStore = defineStore('user', () => { loading.value = true await pb.collection('users').authWithPassword(email, password) await initUser() + // 首次登录设置默认状态为空闲 + if (user.value && !user.value.status) { + await setStatus('idle') + } } catch (error: any) { throw new Error('邮箱或密码错误') } finally {