Skip to content

Commit 8a01f11

Browse files
committed
fix: up
1 parent 252193c commit 8a01f11

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

web/src/modules/auth/AuthorizationCheck.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function AuthorizationCheck() {
1414
const router = useRouter();
1515
const pathname = usePathname();
1616
const [isChecking, setIsChecking] = useState(true);
17+
const [shouldRedirect, setShouldRedirect] = useState(false);
1718

1819
useEffect(() => {
1920
// Skip check if on access-denied page
@@ -24,25 +25,39 @@ export function AuthorizationCheck() {
2425

2526
// Wait for session to load
2627
if (status === "loading") {
28+
setIsChecking(true);
29+
return;
30+
}
31+
32+
// If unauthenticated, no need to check authorization
33+
if (status === "unauthenticated") {
34+
setIsChecking(false);
35+
setShouldRedirect(false);
2736
return;
2837
}
2938

3039
// Check authorization when session is loaded
3140
if (status === "authenticated" && session) {
3241
if (session.unauthorized) {
33-
// Redirect immediately without showing content
42+
// Mark for redirect and keep checking state true
43+
setShouldRedirect(true);
44+
setIsChecking(true);
3445
router.push("/access-denied");
3546
return;
3647
}
3748
}
3849

3950
// Authorization check complete
4051
setIsChecking(false);
52+
setShouldRedirect(false);
4153
}, [session, status, pathname, router]);
4254

43-
// Show loading overlay while checking authorization
55+
// Show loading overlay while checking authorization or redirecting
4456
// This prevents flash of unauthorized content
45-
if (isChecking && pathname !== "/access-denied" && pathname !== "/") {
57+
if (
58+
(isChecking && pathname !== "/access-denied") ||
59+
(shouldRedirect && pathname !== "/access-denied")
60+
) {
4661
return (
4762
<div
4863
style={{

web/src/modules/layout/LayoutWrapper.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,15 @@ export const LayoutWrapper = ({ children }: Props) => {
7272
{
7373
iconId: "fr-icon-account-circle-line",
7474
text: user?.name || user?.email || "Mon compte",
75+
buttonProps: undefined,
76+
linkProps: {
77+
href: "#",
78+
onClick: (e: React.MouseEvent) => e.preventDefault(),
79+
},
80+
},
81+
{
82+
iconId: "fr-icon-logout-box-r-line",
83+
text: "Se déconnecter",
7584
buttonProps: {
7685
onClick: handleSignOut,
7786
},

0 commit comments

Comments
 (0)