chore: refresh user session when user first enter the web

This commit is contained in:
ValdiANS
2026-01-02 12:40:07 +07:00
parent 00f09364b1
commit b53c8b99a0
+13 -8
View File
@@ -29,8 +29,8 @@ const RequireAuth = ({ children }: RequireAuthProps) => {
>('/sso/userinfo', httpClientFetcher, { >('/sso/userinfo', httpClientFetcher, {
shouldRetryOnError: false, shouldRetryOnError: false,
// refresh every 13 minutes // refresh every 12 minutes
refreshInterval: 13 * 60 * 1000, refreshInterval: 12 * 60 * 1000,
}); });
useEffect(() => { useEffect(() => {
@@ -61,12 +61,20 @@ const RequireAuth = ({ children }: RequireAuthProps) => {
async () => { async () => {
await AuthApi.refresh(); await AuthApi.refresh();
}, },
13 * 60 * 1000 12 * 60 * 1000
); );
return () => clearInterval(interval); return () => clearInterval(interval);
}, []); }, []);
useEffect(() => {
const refreshUserSession = async () => {
await AuthApi.refresh();
};
refreshUserSession();
}, []);
if ( if (
(isLoadingUserResponse && !userResponse && !userErrorResponse) || (isLoadingUserResponse && !userResponse && !userErrorResponse) ||
(!userResponse && !userErrorResponse) (!userResponse && !userErrorResponse)
@@ -78,7 +86,7 @@ const RequireAuth = ({ children }: RequireAuthProps) => {
); );
} }
if (userErrorResponse) { if (!isLoadingUserResponse && userErrorResponse) {
return ( return (
<div className='w-full h-screen flex flex-col justify-center items-center gap-4'> <div className='w-full h-screen flex flex-col justify-center items-center gap-4'>
<h2 className='text-2xl font-bold text-error'>Authentication Failed</h2> <h2 className='text-2xl font-bold text-error'>Authentication Failed</h2>
@@ -86,10 +94,7 @@ const RequireAuth = ({ children }: RequireAuthProps) => {
Please try refreshing the page or contact support if the problem Please try refreshing the page or contact support if the problem
persists. persists.
</p> </p>
<button <button className='btn btn-primary' onClick={() => redirectToSSO()}>
className='btn btn-primary'
onClick={() => window.location.reload()}
>
Retry Retry
</button> </button>
</div> </div>