From 0205351d118e9de1138ad40f9bf7c60ea61592aa Mon Sep 17 00:00:00 2001 From: JasonFraser Date: Tue, 24 Nov 2026 08:16:23 -0400 Subject: [PATCH] Fix isAuthenticated to also check pb.authStore token validity !!state.user alone 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 with nothing clearing it automatically. Root cause of a reported "my documents disappeared and uploads fail with 'The requested resource wasn't found'" symptom: the full authenticated shell kept rendering while every PocketBase call silently ran as unauthenticated. Now checks pb.authStore.isValid (decodes the token's own exp claim) too. Co-Authored-By: Claude Sonnet 5 --- frontend/src/stores/authStore.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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. */