Skip to content

Commit 1b0625a

Browse files
author
bhavabhuthi
committed
fix: force login for dashboard pages only
1 parent 1fcc70c commit 1b0625a

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

components/SessionGuard.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
'use client';
22

33
import { ReactNode, useEffect } from 'react';
4+
import { usePathname } from 'next/navigation';
45
import { signIn, useSession } from 'next-auth/react';
56

67
export default function SessionGuard({ children }: { children: ReactNode }) {
78
const { data } = useSession();
9+
10+
const pathname = usePathname();
11+
812
useEffect(() => {
9-
if (data?.error === 'RefreshAccessTokenError') {
13+
if (
14+
data?.error === 'RefreshAccessTokenError' &&
15+
pathname.includes('dashboard')
16+
) {
1017
signIn('keycloak');
1118
}
1219
}, [data]);

0 commit comments

Comments
 (0)