-
Notifications
You must be signed in to change notification settings - Fork 0
Protected route 설정 / MyPage 이메일 변경칸 삭제 #65
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,156 +1,18 @@ | ||
| import "./App.css"; | ||
| import PublicLayout from "./layout/PublicLayout"; | ||
| import { | ||
| createBrowserRouter, | ||
| Navigate, | ||
| RouterProvider, | ||
| type RouteObject, | ||
| } from "react-router-dom"; | ||
| import MainPage from "./pages/MainPage"; | ||
| import ErrorPage from "./pages/ErrorPage"; | ||
| import LoginPage from "./pages/LoginPage.tsx"; | ||
| import SearchPage from "./pages/SearchPage"; | ||
| import { AuthProvider } from "./context/AuthContext.tsx"; | ||
| import PostWrite from "./pages/Post/PostWritePage.tsx"; | ||
| import PostSuccess from "./pages/Post/PostSuccess.tsx"; | ||
| import RandomFeedPage from "./pages/RandomFeedPage.tsx"; | ||
| import LuckyDrawPage from "./pages/LuckyDrawPage.tsx"; | ||
| import MyPageLayout from "./pages/MyPage/MyPageLayout.tsx"; | ||
| import PostDetailPage from "./pages/Post/PostDetailPage.tsx"; | ||
| import FavoriteFeedPage from "./pages/FavoriteFeedPage.tsx"; | ||
| import CategoryFeedPage from "./pages/CategoryFeedPage.tsx"; | ||
| import BestFeedPage from "./pages/BestFeedPage.tsx"; | ||
| import ServiceTerm from "./components/Terms/ServiceTerm.tsx"; | ||
| import PrivacyTerms from "./components/Terms/PrivacyTerms.tsx"; | ||
| import MarketingTerm from "./components/Terms/Marketing.tsx"; | ||
| import ProfileEditPage from "./pages/MyPage/ProfileEditPage.tsx"; | ||
| import MyPostPage from "./pages/MyPage/MyPostPage.tsx"; | ||
| import MyLessonPage from "./pages/MyPage/MyLessonPage.tsx"; | ||
| import SignUpPage from "./pages/SignUp/SignUpPage.tsx"; | ||
| import FindPasswordPage from "./pages/FindPasswordPage.tsx"; | ||
| import SetNewPassWordPage from "./pages/SetNewPasswordPage.tsx"; | ||
| import PostEditPage from "./pages/Post/PostEditPage.tsx"; | ||
| import { createBrowserRouter, RouterProvider } from "react-router-dom"; | ||
| import { AuthProvider } from "./context/AuthContext"; | ||
|
|
||
| //로그인 구현 필요 없이 들어가는 페이지 라우터 | ||
| const publicRoutes: RouteObject[] = [ | ||
| { | ||
| path: "/", | ||
| element: <PublicLayout />, | ||
| children: [ | ||
| { | ||
| // path : "" 와 동일함 -> 하지만 react 에서 index: true를 적극 권장 | ||
| index: true, | ||
| element: <MainPage />, | ||
| }, | ||
| { | ||
| path: "login", | ||
| element: <LoginPage />, | ||
| }, | ||
| //TODO: login 사항 없도록 라우터 분리 | ||
| { | ||
| path: "terms1", | ||
| element: <ServiceTerm />, | ||
| }, | ||
| { | ||
| path: "terms2", | ||
| element: <PrivacyTerms />, | ||
| }, | ||
| { | ||
| path: "terms3", | ||
| element: <MarketingTerm />, | ||
| }, | ||
| ///////////////////////// | ||
| { | ||
| path: "signup", | ||
| element: <SignUpPage />, | ||
| }, | ||
| { | ||
| path: "find-password", | ||
| element: <FindPasswordPage /> | ||
| }, | ||
| { | ||
| path: "set-password", | ||
| element: <SetNewPassWordPage /> | ||
| }, | ||
| { | ||
| path: "search", | ||
| element: <SearchPage />, | ||
| }, | ||
| { | ||
| path: "random-feed", | ||
| element: <RandomFeedPage />, | ||
| }, | ||
| { | ||
| path: "lucky-draw", | ||
| element: <LuckyDrawPage />, | ||
| }, | ||
| { | ||
| path: "favorite-feed", | ||
| element: <FavoriteFeedPage />, | ||
| }, | ||
| { | ||
| path: "category-feed/:categoryId", | ||
| element: <CategoryFeedPage />, | ||
| }, | ||
| { | ||
| path: "best-failer", | ||
| element: <BestFeedPage />, | ||
| }, | ||
| { | ||
| path: "my-profile", | ||
| element: <MyPageLayout />, | ||
| children: [ | ||
| { index: true, element: <Navigate to="profile" replace /> }, | ||
| { path: "profile", element: <ProfileEditPage /> }, | ||
| { path: "posts", element: <MyPostPage /> }, | ||
| { path: "lessons", element: <MyLessonPage /> }, | ||
| ], | ||
| }, | ||
| // 설정한 path 이외에 모든 Path 에 대해 ErrorPage 랜더링 | ||
| { | ||
| path: "*", | ||
| element: <ErrorPage />, | ||
| }, | ||
| { | ||
| path: "post", | ||
| element: <PostWrite />, | ||
| }, | ||
| { | ||
| path: "posts/edit/:postId", | ||
| element: <PostEditPage /> | ||
| }, | ||
| import { publicRoutes } from "./routes/publicRoutes"; | ||
| import { protectedRoutes } from "./routes/protectedRoutes"; | ||
|
|
||
| { | ||
| path: "post/success", | ||
| element: <PostSuccess />, | ||
| }, | ||
| { | ||
| path: "posts/:postId", | ||
| element: <PostDetailPage />, | ||
| }, | ||
| ], | ||
| }, | ||
| ]; | ||
| const router = createBrowserRouter([...publicRoutes, ...protectedRoutes]); | ||
|
|
||
| //router 생성 : 이후 portected를 위해 배열로 넣음 | ||
| const router = createBrowserRouter([...publicRoutes]); | ||
|
|
||
| /* | ||
| useQueryClient 사용을 위해 코드 생성 후 주석 처리 | ||
| export const queryClient = new QueryClient(); | ||
| */ | ||
|
|
||
| // 이후 쿼리, authprovider 사용을 위해 주석 처리 | ||
| function App() { | ||
| return ( | ||
| <> | ||
| <AuthProvider> | ||
| {/* <QueryClientProvider client={queryClient} */} | ||
| <RouterProvider router={router} /> | ||
| {/* </QueryClientProvider> */} | ||
| </AuthProvider> | ||
| </> | ||
| <AuthProvider> | ||
| <RouterProvider router={router} /> | ||
| </AuthProvider> | ||
| ); | ||
| } | ||
|
|
||
| export default App; | ||
| export default App; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,5 +23,6 @@ export const postSignUp = async ({ | |
| verificationToken, | ||
| } | ||
| ); | ||
| console.log("회원가입", data); | ||
| return data; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,6 @@ export const editMyProfile = async ({ | |
| "Content-Type": "multipart/form-data", | ||
| }, | ||
| }); | ||
|
|
||
| return data; | ||
| }; | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jangyeeunee marked this conversation as resolved.
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { Navigate } from "react-router-dom"; | ||
| import { useAuth } from "../context/AuthContext"; | ||
|
|
||
| export const ProtectedRoute = ({ children }: { children: React.ReactNode }) => { | ||
| const { isAuthenticated, isLoading } = useAuth(); | ||
|
|
||
| if (isLoading) return <div>로딩 중...</div>; | ||
|
|
||
| if (!isAuthenticated) { | ||
| alert("로그인이 필요한 서비스입니다."); | ||
| return <Navigate to="/login" replace />; | ||
| } | ||
|
|
||
| return <>{children}</>; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import type { RouteObject } from "react-router-dom"; | ||
| import { Navigate } from "react-router-dom"; | ||
| import PublicLayout from "../layout/PublicLayout"; | ||
|
|
||
| import { ProtectedRoute } from "./ProtectedRoute"; | ||
|
|
||
| import PostWrite from "../pages/Post/PostWritePage"; | ||
| import PostSuccess from "../pages/Post/PostSuccess"; | ||
| import PostEditPage from "../pages/Post/PostEditPage"; | ||
|
|
||
| import MyPageLayout from "../pages/MyPage/MyPageLayout"; | ||
| import ProfileEditPage from "../pages/MyPage/ProfileEditPage"; | ||
| import MyPostPage from "../pages/MyPage/MyPostPage"; | ||
| import MyLessonPage from "../pages/MyPage/MyLessonPage"; | ||
|
|
||
| export const protectedRoutes: RouteObject[] = [ | ||
| { | ||
| path: "/", | ||
| element: <PublicLayout />, | ||
| children: [ | ||
| // 글쓰기 | ||
| { | ||
| path: "post", | ||
| element: ( | ||
| <ProtectedRoute> | ||
| <PostWrite /> | ||
| </ProtectedRoute> | ||
| ), | ||
| }, | ||
| // 작성 성공 | ||
| { | ||
| path: "post/success", | ||
| element: ( | ||
| <ProtectedRoute> | ||
| <PostSuccess /> | ||
| </ProtectedRoute> | ||
| ), | ||
| }, | ||
| // 수정 | ||
| { | ||
| path: "posts/edit/:postId", | ||
| element: ( | ||
| <ProtectedRoute> | ||
| <PostEditPage /> | ||
| </ProtectedRoute> | ||
| ), | ||
| }, | ||
|
|
||
| // 마이페이지 전체 보호 | ||
| { | ||
| path: "my-profile", | ||
| element: ( | ||
| <ProtectedRoute> | ||
| <MyPageLayout /> | ||
| </ProtectedRoute> | ||
| ), | ||
| children: [ | ||
| { index: true, element: <Navigate to="profile" replace /> }, | ||
| { path: "profile", element: <ProfileEditPage /> }, | ||
| { path: "posts", element: <MyPostPage /> }, | ||
| { path: "lessons", element: <MyLessonPage /> }, | ||
| ], | ||
| }, | ||
| ], | ||
| }, | ||
| ]; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
아 이거 protectedRouter 따로 배열로 만들어가지고 넣어주기만 하면 되는데