diff --git a/src/app/page.tsx b/src/app/page.tsx index 2f22f5aa..cc933d52 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -2,17 +2,30 @@ import { useEffect } from 'react'; import { useRouter } from 'next/navigation'; +import { useAuth } from '@/services/hooks/useAuth'; +import { redirectToSSO } from '@/lib/auth-helper'; export default function Home() { + const { user, isLoadingUser } = useAuth(); + const router = useRouter(); useEffect(() => { router.replace('/dashboard'); - }, [router]); + }, [user, isLoadingUser]); - return ( -
- -
- ); + if (isLoadingUser) { + return ( +
+ +
+ ); + } + + if (!isLoadingUser && !user) { + redirectToSSO(); + return; + } + + return null; } diff --git a/src/components/helper/RequireAuth.tsx b/src/components/helper/RequireAuth.tsx index 22b22b03..8fc604ab 100644 --- a/src/components/helper/RequireAuth.tsx +++ b/src/components/helper/RequireAuth.tsx @@ -45,6 +45,10 @@ const RequireAuth = ({ children }: RequireAuthProps) => { } }, [userErrorResponse, setUser]); + useEffect(() => { + setIsLoadingUser(isLoadingUserResponse); + }, [isLoadingUserResponse]); + if ( (isLoadingUserResponse && !userResponse && !userErrorResponse) || (!userResponse && !userErrorResponse)