-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New : 보호된 라우트 레이아웃 구현 * New : 로그인 기능 개선 * New : Protected Route 구현에 따른 디렉토리 구조 변경
- Loading branch information
1 parent
b4346d7
commit 122ae9f
Showing
17 changed files
with
115 additions
and
23 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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,9 @@ | ||
import useLogoutOnlyProtector from "@/hooks/useLogoutOnlyProtector"; | ||
import { ReactNode } from "react"; | ||
|
||
const LogoutOnlyLayout = async ({ children }: { children: ReactNode }) => { | ||
useLogoutOnlyProtector(); | ||
return <>{children}</>; | ||
}; | ||
|
||
export default LogoutOnlyLayout; |
This file contains 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,9 @@ | ||
import useAuthProtector from "@/hooks/useAuthProtector"; | ||
import { ReactNode } from "react"; | ||
|
||
const AuthProtectorlayout = async ({ children }: { children: ReactNode }) => { | ||
useAuthProtector(); | ||
return <>{children}</>; | ||
}; | ||
|
||
export default AuthProtectorlayout; |
This file contains 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,3 @@ | ||
export default function NewpostPage() { | ||
return <>페지이</>; | ||
} |
This file contains 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,12 @@ | ||
import ModalWrapper from "@/components/ModalWrapper"; | ||
import React, { ReactNode } from "react"; | ||
|
||
type Props = { | ||
children: ReactNode; | ||
}; | ||
|
||
const NewPostPage = ({ children }: Props) => { | ||
return <ModalWrapper>{children}</ModalWrapper>; | ||
}; | ||
|
||
export default NewPostPage; |
This file contains 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,19 @@ | ||
import { LOGIN_API_PATH } from "@/const/serverPath"; | ||
import { setCookie } from "@/hooks/useSetCookie"; | ||
import axios from "@/libs/axios"; | ||
import { SigninResponseInterface } from "@/types/auth/signinResponse"; | ||
import { NextRequest, NextResponse } from "next/server"; | ||
|
||
export async function POST(request: NextRequest) { | ||
const { id, password } = await request.json(); | ||
try { | ||
const { data } = await axios.post<SigninResponseInterface>(LOGIN_API_PATH, { | ||
id, | ||
password, | ||
}); | ||
setCookie({ key: "accessToken", value: data.token, httpOnly: true }); | ||
return NextResponse.json({ ...data }); | ||
} catch { | ||
return NextResponse.json({ message: "로그인 실패" }, { status: 400 }); | ||
} | ||
} |
This file contains 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 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 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 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 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 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,14 @@ | ||
import { SIGNIN } from "@/const/clientPath"; | ||
import { cookies } from "next/headers"; | ||
import { redirect } from "next/navigation"; | ||
/** | ||
* 쿠키에 accessToken 이나 refreshToken이 없을 경우 로그인 페이지로 리다이렉트 시키는 훅스 | ||
*/ | ||
export default function useAuthProtector() { | ||
const cookieStore = cookies(); | ||
const accessToken = cookieStore.get("accessToken")?.value; | ||
|
||
if (!accessToken) { | ||
redirect(SIGNIN); | ||
} | ||
} |
This file contains 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 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,14 @@ | ||
import HOME from "@/const/clientPath"; | ||
import { cookies } from "next/headers"; | ||
import { redirect } from "next/navigation"; | ||
/** | ||
* 쿠키에 accessToken 이나 refreshToken이 있을경우 메인페이지로 리다이렉트 시키는 훅스 | ||
*/ | ||
export default function useLogoutProtector() { | ||
const cookieStore = cookies(); | ||
const accessToken = cookieStore.get("accessToken")?.value; | ||
|
||
if (accessToken) { | ||
redirect(HOME); | ||
} | ||
} |
This file contains 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