fix: redirect to SSO if user isnt exist and show loading state if still loading user

This commit is contained in:
ValdiANS
2025-12-10 16:57:45 +07:00
parent 83d76f7de4
commit 017b081832
+14 -1
View File
@@ -2,17 +2,30 @@
import { useEffect } from 'react'; import { useEffect } from 'react';
import { useRouter } from 'next/navigation'; import { useRouter } from 'next/navigation';
import { useAuth } from '@/services/hooks/useAuth';
import { redirectToSSO } from '@/lib/auth-helper';
export default function Home() { export default function Home() {
const { user, isLoadingUser } = useAuth();
const router = useRouter(); const router = useRouter();
useEffect(() => { useEffect(() => {
router.replace('/dashboard'); router.replace('/dashboard');
}, [router]); }, [user, isLoadingUser]);
if (isLoadingUser) {
return ( return (
<main className='w-full h-full min-h-screen flex flex-row justify-center items-center'> <main className='w-full h-full min-h-screen flex flex-row justify-center items-center'>
<span className='loading loading-spinner loading-lg'></span> <span className='loading loading-spinner loading-lg'></span>
</main> </main>
); );
}
if (!isLoadingUser && !user) {
redirectToSSO();
return;
}
return null;
} }