feat(frontend): wait for auth
vi did:web:vt3e.cat
Sat, 09 May 2026 04:36:09 +0100
2 files changed,
12 insertions(+),
2 deletions(-)
M
frontend/src/router/index.ts
→
frontend/src/router/index.ts
@@ -28,8 +28,11 @@ },
], }); -router.beforeEach((to, _from, next) => { - const isAuthenticated = useAuthStore().isAuthenticated; +router.beforeEach(async (to, _from, next) => { + const authStore = useAuthStore(); + await authStore.waitForAuth(); + const isAuthenticated = authStore.isAuthenticated; + if (to.name !== "Login" && !isAuthenticated) { next({ name: "Login" }); } else {
M
frontend/src/stores/auth.ts
→
frontend/src/stores/auth.ts
@@ -15,9 +15,16 @@ isAuthenticated.value = true;
} catch {} } + async function waitForAuth() { + while (!isAuthenticated.value) { + await getUser(); + } + } + return { isAuthenticated, user, getUser, + waitForAuth, }; });