Skip to content

Commit

Permalink
fix: warning about component update
Browse files Browse the repository at this point in the history
  • Loading branch information
aldbr committed Apr 8, 2024
1 parent 6972417 commit 640fac4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
12 changes: 7 additions & 5 deletions src/components/applications/LoginForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -84,11 +91,6 @@ export function LoginForm() {
});
}
};
// Redirect to dashboard if already authenticated
if (isAuthenticated) {
router.push("/dashboard");
return null;
}

if (isLoading) {
return <div>Loading...</div>;
Expand Down
13 changes: 7 additions & 6 deletions src/components/layout/OIDCSecure.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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}</>;
}

0 comments on commit 640fac4

Please sign in to comment.