diff --git a/frontend/src/stores/authStore.js b/frontend/src/stores/authStore.js index d96322b..3240824 100644 --- a/frontend/src/stores/authStore.js +++ b/frontend/src/stores/authStore.js @@ -14,7 +14,22 @@ export const useAuthStore = defineStore('auth', { user: pb.authStore.record, }), getters: { - isAuthenticated: (state) => !!state.user, + // !!state.user alone isn't enough - it only reflects whether a user + // record was ever persisted (login), not whether that session's + // token is STILL VALID. pb.authStore keeps the record around across + // a token's own expiry (nothing clears it automatically), so a + // user who closes the app and comes back after the session's own + // duration (users.authToken.duration, 5 days by default) would + // otherwise see the full authenticated shell while every + // PocketBase call silently runs as if unauthenticated (listRule/ + // viewRule's own `owner = @request.auth.id` matches nothing) - + // confirmed for real as the root cause of a reported "my documents + // disappeared and uploads fail with 'The requested resource wasn't + // found'" report, not a data-loss or extraction bug. pb.authStore + // .isValid decodes the token's own exp claim, so this getter now + // correctly flips to false the next time it's evaluated (at latest, + // on the next full page load) once the token has actually expired. + isAuthenticated: (state) => !!state.user && pb.authStore.isValid, }, actions: { /** Registered once from main.js - keeps this store's user in sync with the SDK's real auth state. */