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

View File

@@ -244,6 +244,7 @@ import UserRegistrationForm from "~/components/Domain/User/UserRegistrationForm.
definePageMeta({ definePageMeta({
layout: "blank", layout: "blank",
middleware: ["admin-only"],
}); });
// ================================================================ // ================================================================
@@ -264,13 +265,6 @@ useSeoMeta({
title: i18n.t("admin.setup.first-time-setup"), title: i18n.t("admin.setup.first-time-setup"),
}); });
if (!$auth.loggedIn.value) {
router.push("/login");
}
else if (!$auth.user.value?.admin) {
router.push(groupSlug.value ? `/g/${groupSlug.value}` : "/login");
}
enum Pages { enum Pages {
LANDING = 0, LANDING = 0,
USER_INFO = 1, USER_INFO = 1,

View File

@@ -0,0 +1,9 @@
export default defineNuxtPlugin({
async setup() {
const auth = useAuthBackend();
console.debug("Initializing auth plugin");
await auth.getSession();
console.debug("Auth plugin initialized");
},
});