add log statements + remove auto redirect

This commit is contained in:
Hayden 2023-12-15 21:28:19 -06:00
parent 8538877f52
commit d048b91a0c
No known key found for this signature in database
GPG key ID: 17CF79474E257545
3 changed files with 3 additions and 3 deletions

View file

@ -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 = "/";
}
}
});

View file

@ -71,6 +71,7 @@ class AuthContext implements IAuthContext {
}
isAuthorized() {
console.debug("isAuthorized", this.token);
return this.token;
}

View file

@ -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("/");
}
}