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 <noreply@anthropic.com>
This commit is contained in:
parent
8a99254d28
commit
0205351d11
|
|
@ -14,7 +14,22 @@ export const useAuthStore = defineStore('auth', {
|
||||||
user: pb.authStore.record,
|
user: pb.authStore.record,
|
||||||
}),
|
}),
|
||||||
getters: {
|
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: {
|
actions: {
|
||||||
/** Registered once from main.js - keeps this store's user in sync with the SDK's real auth state. */
|
/** Registered once from main.js - keeps this store's user in sync with the SDK's real auth state. */
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue