Skip to content

Commit

Permalink
Feat(user): 인증 화면 가드 구성
Browse files Browse the repository at this point in the history
- 사용자가 로그인 중일 때는 인증 화면으로 갈 수 없도록 구현

ref: #67
  • Loading branch information
hwna00 committed Sep 25, 2023
1 parent 1c56f70 commit 3ed14b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
16 changes: 16 additions & 0 deletions packages/apps/user/src/components/Root/AuthRoot.js
Original file line number Diff line number Diff line change
@@ -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 ? <LoadingPage /> : user ? navigate('/') : <Outlet />}</>
);
};

export default AuthRoot;
2 changes: 1 addition & 1 deletion packages/apps/user/src/components/Root/Root.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const Root = function () {

return (
<>
{true ? (
{userLoading ? (
<LoadingPage />
) : user ? (
<>
Expand Down
5 changes: 2 additions & 3 deletions packages/apps/user/src/routes/authRoutes.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: <Outlet />,
element: <AuthRoot />,
errorElement: <NotFound />,
children: [
{
Expand Down

0 comments on commit 3ed14b3

Please sign in to comment.