fixes auth?

This commit is contained in:
2025-08-02 15:35:18 +02:00
parent 78dc7be703
commit b1deaee4e6
4 changed files with 36 additions and 7 deletions
+18 -1
View File
@@ -1,7 +1,7 @@
"use client";
import { useAuth } from "react-oidc-context";
import { useState, useEffect } from "react";
import { useRouter } from "next/navigation";
import { useRouter, usePathname } from "next/navigation";
import { Source_Sans_3, Nunito } from "next/font/google";
const nunito = Nunito({
@@ -11,6 +11,7 @@ const nunito = Nunito({
export default function AuthStatus() {
const auth = useAuth();
const router = useRouter();
const pathname = usePathname();
const [persistentAuthState, setPersistentAuthState] = useState<{
isAuthenticated: boolean;
user: any;
@@ -32,6 +33,22 @@ export default function AuthStatus() {
}
}, [auth.isLoading, auth.isAuthenticated, auth.user, auth.error]);
useEffect(() => {
// Redirect to / if user is definitely not logged in and not already on /
if (
persistentAuthState.hasInitialized &&
!persistentAuthState.isAuthenticated &&
pathname !== "/"
) {
router.push("/");
}
}, [
persistentAuthState.hasInitialized,
persistentAuthState.isAuthenticated,
pathname,
router,
]);
// Show loading only on first load, not on subsequent navigations
if (!persistentAuthState.hasInitialized && auth.isLoading) {
return (