-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from shimdokite/mainPage
[FE] ✨ 페이지 접근 권한 구현
- Loading branch information
Showing
12 changed files
with
92 additions
and
37 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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,21 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
import { ADMIN_USER_ID } from '@/constants/values'; | ||
|
||
export const config = { | ||
matcher: ['/((?!api|_next/static|_next/image|favicon.ico|fonts|images).*)'], | ||
}; | ||
|
||
const protectedPage = ['/admin']; | ||
|
||
export function middleware(request: NextRequest) { | ||
const userId = String(request.cookies.get('userId')); | ||
const currentPath = request.nextUrl.pathname; | ||
|
||
if (userId !== ADMIN_USER_ID && protectedPage.includes(currentPath)) { | ||
const url = request.nextUrl.clone(); | ||
url.pathname = '/'; | ||
|
||
return NextResponse.redirect(url); | ||
} | ||
} |
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,7 @@ | ||
import Cookies from 'js-cookie'; | ||
|
||
const removeCookiesForUserId = () => { | ||
return Cookies.remove('userId'); | ||
}; | ||
|
||
export default removeCookiesForUserId; |
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,7 @@ | ||
import Cookies from 'js-cookie'; | ||
|
||
const setCookiesByUserId = (userId: string) => { | ||
return Cookies.set('userId', userId, { expires: 1 }); | ||
}; | ||
|
||
export default setCookiesByUserId; |