diff --git a/client/src/components/auth/HandleAuth.jsx b/client/src/components/auth/HandleAuth.jsx index 4c9d6abb4..e54eec6cc 100644 --- a/client/src/components/auth/HandleAuth.jsx +++ b/client/src/components/auth/HandleAuth.jsx @@ -1,7 +1,8 @@ -import React, { useState, useEffect } from 'react'; +import { useState, useEffect } from 'react'; import { Redirect } from 'react-router-dom'; import { isValidToken } from '../../services/user.service'; import { authLevelRedirect } from '../../utils/authUtils'; +import { Box, CircularProgress, Typography } from '@mui/material'; import '../../sass/MagicLink.scss'; import useAuth from '../../hooks/useAuth'; @@ -33,30 +34,22 @@ const HandleAuth = (props) => { // Step 3: Set IsLoaded value to render Component useEffect(() => { - if (!isMagicLinkValid) { - setIsLoaded(true); - return; - } + if (!isMagicLinkValid) return; if (!auth || auth.isError) return; setIsLoaded(true); }, [isMagicLinkValid, setIsLoaded, auth]); - if (!isLoaded) return
Loading...
; - - const Delayed = ({ children, waitBeforeShow = 500 }) => { - const [isShown, setIsShown] = useState(false); - useEffect(() => { + useEffect(() => { + if (!isLoaded) { const timer = setTimeout(() => { - setIsShown(true); - }, waitBeforeShow); + setIsLoaded(true); + }, 1000); return () => clearTimeout(timer); - }, [waitBeforeShow]); - - return isShown ? children : null; - }; + } + }, [isLoaded]); let loginRedirect = ''; @@ -65,12 +58,16 @@ const HandleAuth = (props) => { } return ( -
- -
Sorry, the link is not valid anymore.
-
+ + {!isLoaded ? ( + + ) : ( + + Sorry, the link is not valid anymore. + + )} {auth?.user && /* Redirect to /welcome */} -
+ ); };