mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-10-27 00:04:23 -04:00
fix: No Redirect On Valid Token (#6327)
This commit is contained in:
@@ -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),
|
||||||
|
|||||||
@@ -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,
|
||||||
|
|||||||
9
frontend/plugins/init-auth.client.ts
Normal file
9
frontend/plugins/init-auth.client.ts
Normal 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");
|
||||||
|
},
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user