diff --git a/src/components/applications/LoginForm.tsx b/src/components/applications/LoginForm.tsx
index d3841a63..968c959f 100644
--- a/src/components/applications/LoginForm.tsx
+++ b/src/components/applications/LoginForm.tsx
@@ -42,6 +42,13 @@ export function LoginForm() {
}
}, [configuration, isAuthenticated, login]);
+ useEffect(() => {
+ // Redirect to dashboard if already authenticated
+ if (isAuthenticated) {
+ router.push("/dashboard");
+ }
+ }, [isAuthenticated, router]);
+
// Get default group
const getDefaultGroup = (data: Metadata | undefined, vo: string): string => {
if (!data) {
@@ -84,11 +91,6 @@ export function LoginForm() {
});
}
};
- // Redirect to dashboard if already authenticated
- if (isAuthenticated) {
- router.push("/dashboard");
- return null;
- }
if (isLoading) {
return
Loading...
;
diff --git a/src/components/layout/OIDCSecure.tsx b/src/components/layout/OIDCSecure.tsx
index 6ca7ea5a..6e757b87 100644
--- a/src/components/layout/OIDCSecure.tsx
+++ b/src/components/layout/OIDCSecure.tsx
@@ -1,5 +1,5 @@
"use client";
-import React from "react";
+import React, { useEffect } from "react";
import { useRouter } from "next/navigation";
import { useOidc } from "@axa-fr/react-oidc";
import { useOIDCContext } from "@/hooks/oidcConfiguration";
@@ -18,11 +18,12 @@ export function OIDCSecure({ children }: OIDCProps) {
const { isAuthenticated } = useOidc(configuration?.scope);
const router = useRouter();
- // Redirect to login page if not authenticated
- if (!isAuthenticated) {
- router.push("/auth");
- return null;
- }
+ useEffect(() => {
+ // Redirect to login page if not authenticated
+ if (!isAuthenticated) {
+ router.push("/auth");
+ }
+ }, [isAuthenticated, router]);
return <>{children}>;
}