mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
hotfix: Implement client-side dashboard redirect with loading spinner, improve authentication error handling by clearing user state on 401, and extend SSO redirect loop protection.
This commit is contained in:
+10
-3
@@ -1,11 +1,18 @@
|
|||||||
import { redirect } from 'next/navigation';
|
'use client';
|
||||||
|
|
||||||
|
import { useEffect } from 'react';
|
||||||
|
import { useRouter } from 'next/navigation';
|
||||||
|
|
||||||
export default function Home() {
|
export default function Home() {
|
||||||
redirect('/dashboard');
|
const router = useRouter();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
router.replace('/dashboard');
|
||||||
|
}, [router]);
|
||||||
|
|
||||||
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'>
|
||||||
<h1>LTI ERP</h1>
|
<span className='loading loading-spinner loading-lg'></span>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,11 +38,17 @@ const RequireAuth = ({ children }: RequireAuthProps) => {
|
|||||||
// Explicitly handle 401 redirect from the component level
|
// Explicitly handle 401 redirect from the component level
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (userErrorResponse?.response?.status === 401) {
|
if (userErrorResponse?.response?.status === 401) {
|
||||||
|
// Clear cache to prevent stale data from rendering children
|
||||||
|
// mutate('/sso/userinfo', undefined, { revalidate: false }); // Optional: if using global mutate
|
||||||
|
setUser(undefined);
|
||||||
redirectToSSO();
|
redirectToSSO();
|
||||||
}
|
}
|
||||||
}, [userErrorResponse]);
|
}, [userErrorResponse, setUser]);
|
||||||
|
|
||||||
if (isLoadingUserResponse && !userResponse && !userErrorResponse) {
|
if (
|
||||||
|
(isLoadingUserResponse && !userResponse && !userErrorResponse) ||
|
||||||
|
(!userResponse && !userErrorResponse)
|
||||||
|
) {
|
||||||
return (
|
return (
|
||||||
<div className='w-full flex flex-row justify-center items-center p-4'>
|
<div className='w-full flex flex-row justify-center items-center p-4'>
|
||||||
<span className='loading loading-spinner loading-xl' />
|
<span className='loading loading-spinner loading-xl' />
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ export const redirectToSSO = () => {
|
|||||||
const lastRedirect = sessionStorage.getItem('auth_redirect_timestamp');
|
const lastRedirect = sessionStorage.getItem('auth_redirect_timestamp');
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
// Loop protection: allow redirect only if last one was > 2 seconds ago
|
// Loop protection: allow redirect only if last one was > 5 seconds ago
|
||||||
// or if no redirect has happened yet.
|
// or if no redirect has happened yet.
|
||||||
if (!lastRedirect || now - parseInt(lastRedirect, 10) > 2000) {
|
if (!lastRedirect || now - parseInt(lastRedirect, 10) > 5000) {
|
||||||
sessionStorage.setItem('auth_redirect_timestamp', now.toString());
|
sessionStorage.setItem('auth_redirect_timestamp', now.toString());
|
||||||
// const ssoLoginUrl = `${process.env.NEXT_PUBLIC_SSO_LOGIN_URL as string}?redirect_url=${window.location.href}`;
|
// const ssoLoginUrl = `${process.env.NEXT_PUBLIC_SSO_LOGIN_URL as string}?redirect_url=${window.location.href}`;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user