Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FE] 로그인하지 않은 상태에서 페이지에 접근할 때 처리(#551) #552

Merged
merged 6 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/src/components/common/loading/Loading.style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export const LoadingContainer = styled.div`

svg {
position: absolute;
left: 50%;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

Expand All @@ -36,6 +36,7 @@ export const BackDrop = styled.div`

width: 100vw;
height: 100vh;

opacity: 0.4;
background-color: ${({ theme }) => theme.COLOR.black};
`;
18 changes: 18 additions & 0 deletions frontend/src/components/routes/NotFoundRoute.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import * as S from "./PrivateRoute.style";
import { useNavigate } from "react-router-dom";
import Button from "@/components/common/button/Button";
import { errorCharacter } from "@/assets";

const NotFoundRoute = () => {
const navigate = useNavigate();

return (
<S.PrivateRouteContainer>
<img src={errorCharacter} alt="로그인 후 이용해주세요" />
<p>해당 페이지를 찾을 수 없습니다.</p>
<Button onClick={() => navigate("/")}>홈 화면으로 가기</Button>
</S.PrivateRouteContainer>
);
};

export default NotFoundRoute;
20 changes: 20 additions & 0 deletions frontend/src/components/routes/PrivateRoute.style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import styled from "styled-components";

export const PrivateRouteContainer = styled.div`
display: flex;
flex-direction: column;
gap: 2rem;
align-items: center;
justify-content: center;

margin-top: 20%;

img {
width: 50%;
max-width: 250px;
}

p {
font: ${({ theme }) => theme.TEXT.medium_bold};
}
`;
23 changes: 23 additions & 0 deletions frontend/src/components/routes/PrivateRoute.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Button from "../common/button/Button";
import { Outlet, useNavigate } from "react-router-dom";
import * as S from "@/components/routes/PrivateRoute.style";
import { errorCharacter } from "@/assets";

const PrivateRoute = () => {
const navigate = useNavigate();
const isLoggedIn = !!localStorage.getItem("accessToken");

if (isLoggedIn) {
return <Outlet />;
}

return (
<S.PrivateRouteContainer>
<img src={errorCharacter} alt="로그인 후 이용해주세요" />
<p>로그인 후 이용 가능한 페이지입니다.</p>
<Button onClick={() => navigate("/")}>홈 화면으로 가기</Button>
</S.PrivateRouteContainer>
);
};

export default PrivateRoute;
17 changes: 10 additions & 7 deletions frontend/src/pages/callback/CallbackPage.style.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import styled, { keyframes } from "styled-components";
import { theme } from "@/styles/theme";

export const CallbackPageContainer = styled.div`
display: flex;
flex-direction: column;
gap: 1rem;
gap: 2rem;
align-items: center;
justify-content: center;

height: 100%;
margin-top: 20%;
`;

export const Character = styled.img`
width: 300px;
width: 50%;
max-width: 250px;
`;

// LoadingBar
Expand All @@ -36,12 +36,15 @@ export const LoadingContainer = styled.div`
width: 200px;
height: 30px;

font: ${({ theme }) => theme.TEXT.medium};
color: ${({ theme }) => theme.COLOR.grey4};

background-color: ${({ theme }) => theme.COLOR.white};
border: 2px solid ${({ theme }) => theme.COLOR.primary2};
border-radius: 25px;

p {
z-index: 999;
font: ${({ theme }) => theme.TEXT.medium_bold};
color: ${({ theme }) => theme.COLOR.grey4};
}
`;

export const LoadingBar = styled.div`
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/callback/CallbackPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const CallbackPage = () => {
}

const timer = setTimeout(() => {
navigate("/");
navigate("/", { replace: true });
}, 2000);

return () => clearTimeout(timer);
Expand All @@ -27,7 +27,7 @@ const CallbackPage = () => {
<S.CallbackPageContainer>
<S.Character src={thinkingCharacter} alt="로그인 중" />
<S.LoadingContainer>
로그인 중 ...
<p>로그인 중...</p>
<S.LoadingBar />
</S.LoadingContainer>
</S.CallbackPageContainer>
Expand Down
43 changes: 27 additions & 16 deletions frontend/src/router.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import PrivateRoute from "./components/routes/PrivateRoute";
import CallbackPage from "./pages/callback/CallbackPage";
import FeedbackPage from "./pages/feedback/FeedbackPage";
import ProfilePage from "./pages/profile/ProfilePage";
Expand All @@ -6,6 +7,7 @@ import RoomCreatePage from "./pages/roomCreate/RoomCreatePage";
import { lazy } from "react";
import { createBrowserRouter } from "react-router-dom";
import Layout from "@/components/layout/Layout";
import NotFoundRoute from "@/components/routes/NotFoundRoute";
import MainPage from "@/pages/main/MainPage";
import RoomDetailPage from "@/pages/roomDetail/RoomDetailPage";
import UserProfile from "@/pages/userProfile/UserProfile";
Expand All @@ -28,33 +30,42 @@ const router = sentryCreateBrowserRouter([
path: `callback`,
element: <CallbackPage />,
},
{
path: `rooms/:id`,
element: <RoomDetailPage />,
},
{
path: `rooms/create`,
element: <RoomCreatePage />,
},
{
path: `guide`,
element: <GuidePage />,
},
{
path: `profile/:username`,
element: <UserProfile />,
},
// {
// path: `ranking`,
// element: <RankingPage />,
// },
{
path: `feedback`,
element: <FeedbackPage />,
},
{
path: `profile`,
element: <ProfilePage />,
element: <PrivateRoute />,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로그인 상태에 따라 보여주는 거 좋은 것 같네용
다르 의견처럼 존재하지 않는 페이지 접근도 다른 이슈에서 처리해주면 좋을 것 같아요~~

children: [
{
path: `rooms/:id`,
element: <RoomDetailPage />,
},
{
path: `rooms/create`,
element: <RoomCreatePage />,
},
{
path: `feedback`,
element: <FeedbackPage />,
},
{
path: `profile`,
element: <ProfilePage />,
},
],
},
{
path: `profile/:username`,
element: <UserProfile />,
path: "*",
element: <NotFoundRoute />,
},
],
},
Expand Down
Loading