mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
fix: redirect to SSO if user isnt exist and show loading state if still loading user
This commit is contained in:
+19
-6
@@ -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]);
|
||||||
|
|
||||||
return (
|
if (isLoadingUser) {
|
||||||
<main className='w-full h-full min-h-screen flex flex-row justify-center items-center'>
|
return (
|
||||||
<span className='loading loading-spinner loading-lg'></span>
|
<main className='w-full h-full min-h-screen flex flex-row justify-center items-center'>
|
||||||
</main>
|
<span className='loading loading-spinner loading-lg'></span>
|
||||||
);
|
</main>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isLoadingUser && !user) {
|
||||||
|
redirectToSSO();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user