From 3ed14b3bdc52f483f4dc611a6ccc20d71060d21f Mon Sep 17 00:00:00 2001 From: hwna00 Date: Sun, 24 Sep 2023 01:53:22 +0900 Subject: [PATCH] =?UTF-8?q?Feat(user):=20=EC=9D=B8=EC=A6=9D=20=ED=99=94?= =?UTF-8?q?=EB=A9=B4=20=EA=B0=80=EB=93=9C=20=EA=B5=AC=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 사용자가 로그인 중일 때는 인증 화면으로 갈 수 없도록 구현 ref: #67 --- .../apps/user/src/components/Root/AuthRoot.js | 16 ++++++++++++++++ packages/apps/user/src/components/Root/Root.js | 2 +- packages/apps/user/src/routes/authRoutes.js | 5 ++--- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 packages/apps/user/src/components/Root/AuthRoot.js 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: [ {