Added minimal handling of expired tokens

main
Eloi Zalczer 2024-07-04 14:44:31 +02:00
parent 12f7eab798
commit 2985c58dd6
2 changed files with 11 additions and 1 deletions

View File

@ -5,6 +5,14 @@ export const pb = new PocketBase(import.meta.env.VITE_POCKETBASE_URL);
export const currentUser = ref();
if (pb.authStore.isValid) {
try {
await pb.collection("users").authRefresh();
} catch (err) {
pb.authStore.clear();
}
}
pb.authStore.onChange(() => {
currentUser.value = pb.authStore.model;
}, true);

View File

@ -30,7 +30,9 @@ export const usePreferencesStore = defineStore("preferences", {
async init() {
pb.authStore.onChange(async () => {
if (pb.authStore.isValid) {
await this.reset();
}
}, true);
},
},