fix: No Redirect On Valid Token (#6327)

This commit is contained in:
Michael Genson
2025-10-06 13:02:25 -05:00
committed by GitHub
parent 8ab69a7d7a
commit a17b0e329e
3 changed files with 12 additions and 17 deletions

View File

@@ -20,7 +20,7 @@ interface AuthState {
}
const authUser = ref<UserOut | null>(null);
const authStatus = ref<"loading" | "authenticated" | "unauthenticated">("unauthenticated");
const authStatus = ref<"loading" | "authenticated" | "unauthenticated">("loading");
export const useAuthBackend = function (): AuthState {
const { $axios } = useNuxtApp();
@@ -42,7 +42,6 @@ export const useAuthBackend = function (): AuthState {
router.push("/login");
}
}
return false;
}
async function getSession(): Promise<void> {
@@ -59,9 +58,9 @@ export const useAuthBackend = function (): AuthState {
authStatus.value = "authenticated";
}
catch (error: any) {
console.error("Failed to fetch user session:", error);
handleAuthError(error);
authStatus.value = "unauthenticated";
throw error;
}
}
@@ -140,13 +139,6 @@ export const useAuthBackend = function (): AuthState {
}, { immediate: true });
}
// Initialize auth state if token exists
if (import.meta.client && tokenCookie.value && authStatus.value === "unauthenticated") {
getSession().catch((error: any) => {
handleAuthError(error);
});
}
return {
data: computed(() => authUser.value),
status: computed(() => authStatus.value),