From 3ee150e7d66d18c6369d171994932744a614a74f Mon Sep 17 00:00:00 2001 From: Hayden <64056131+hay-kot@users.noreply.github.com> Date: Fri, 15 Dec 2023 21:32:44 -0600 Subject: [PATCH] feat: add log statements + remove auto redirect (#671) --- frontend/composables/use-api.ts | 3 --- frontend/composables/use-auth-context.ts | 1 + frontend/middleware/auth.ts | 2 ++ 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/frontend/composables/use-api.ts b/frontend/composables/use-api.ts index 2eb4f88..5f8dde8 100644 --- a/frontend/composables/use-api.ts +++ b/frontend/composables/use-api.ts @@ -36,9 +36,6 @@ export function useUserApi(): UserClient { if (r.status === 401) { console.error("unauthorized request, invalidating session"); authCtx.invalidateSession(); - if (window.location.pathname !== "/") { - window.location.href = "/"; - } } }); diff --git a/frontend/composables/use-auth-context.ts b/frontend/composables/use-auth-context.ts index 740a303..883a0be 100644 --- a/frontend/composables/use-auth-context.ts +++ b/frontend/composables/use-auth-context.ts @@ -71,6 +71,7 @@ class AuthContext implements IAuthContext { } isAuthorized() { + console.debug("isAuthorized", this.token); return this.token; } diff --git a/frontend/middleware/auth.ts b/frontend/middleware/auth.ts index 2eca73f..97a9920 100644 --- a/frontend/middleware/auth.ts +++ b/frontend/middleware/auth.ts @@ -4,6 +4,7 @@ export default defineNuxtRouteMiddleware(async () => { if (!ctx.isAuthorized()) { if (window.location.pathname !== "/") { + console.debug("[middleware/auth] isAuthorized returned false, redirecting to /"); return navigateTo("/"); } } @@ -13,6 +14,7 @@ export default defineNuxtRouteMiddleware(async () => { const { data, error } = await api.user.self(); if (error) { if (window.location.pathname !== "/") { + console.debug("[middleware/user] user is null and fetch failed, redirecting to /"); return navigateTo("/"); } }