diff --git a/packages/apps/user/src/components/Root/AuthRoot.js b/packages/apps/user/src/components/Root/AuthRoot.js new file mode 100644 index 00000000..525957e8 --- /dev/null +++ b/packages/apps/user/src/components/Root/AuthRoot.js @@ -0,0 +1,16 @@ +import { Outlet, useNavigate } from 'react-router-dom'; + +import useUser from '../../hooks/useUser'; +import LoadingPage from '../../../../../common/LoadingPage'; + +const AuthRoot = function () { + const navigate = useNavigate(); + const { userLoading, user, isLoggedIn } = useUser(); + console.log(userLoading, user, isLoggedIn); + + return ( + <>{userLoading ? : user ? navigate('/') : } + ); +}; + +export default AuthRoot; diff --git a/packages/apps/user/src/components/Root/Root.js b/packages/apps/user/src/components/Root/Root.js index cd4e255e..6bf8af61 100644 --- a/packages/apps/user/src/components/Root/Root.js +++ b/packages/apps/user/src/components/Root/Root.js @@ -13,7 +13,7 @@ const Root = function () { return ( <> - {true ? ( + {userLoading ? ( ) : user ? ( <> diff --git a/packages/apps/user/src/routes/authRoutes.js b/packages/apps/user/src/routes/authRoutes.js index 3f3a9c8b..1150ab41 100644 --- a/packages/apps/user/src/routes/authRoutes.js +++ b/packages/apps/user/src/routes/authRoutes.js @@ -1,5 +1,3 @@ -import { Outlet } from 'react-router-dom'; - import NotFound from '../views/NotFound/NotFound'; import SignUp from '../views/Auth/SignUp/SignUp'; import LogIn from '../views/Auth/LogIn/LogIn'; @@ -9,10 +7,11 @@ import AfterCapture from '../components/SignUpForm/AfterCapture'; import Step1 from '../views/Auth/SignUp/Step1'; import Step2 from '../views/Auth/SignUp/Step2'; import Step3 from '../views/Auth/SignUp/Step3'; +import AuthRoot from '../components/Root/AuthRoot'; const authRoutes = { path: 'auth', - element: , + element: , errorElement: , children: [ {