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
+19 -6
View File
@@ -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 (
<main className='w-full h-full min-h-screen flex flex-row justify-center items-center'>
<span className='loading loading-spinner loading-lg'></span>
</main>
);
if (isLoadingUser) {
return (
<main className='w-full h-full min-h-screen flex flex-row justify-center items-center'>
<span className='loading loading-spinner loading-lg'></span>
</main>
);
}
if (!isLoadingUser && !user) {
redirectToSSO();
return;
}
return null;
}