-
Notifications
You must be signed in to change notification settings - Fork 6
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 #254 from Kernel360/feature-middleware
페이지 기능: middleware 설정
- Loading branch information
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
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,32 @@ | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
const middleware = (request: NextRequest) => { | ||
const { pathname } = request.nextUrl; | ||
const cookie = request.cookies.get('token'); | ||
|
||
let token; | ||
|
||
if (cookie) { | ||
token = cookie.value; | ||
} | ||
|
||
if (!token && ( | ||
pathname === '/my-page' | ||
|| pathname === '/favorite' | ||
|| pathname === '/my-page/car-details' | ||
|| pathname === '/my-page/car-wash-details' | ||
|| pathname === '/my-page/profile' | ||
)) { | ||
return NextResponse.redirect(new URL('/login', request.url)); | ||
} | ||
|
||
return NextResponse.next(); | ||
}; | ||
|
||
export default middleware; | ||
|
||
export const config = { | ||
// Skip all paths that should not be internationalized. This example skips the | ||
// folders "api", "_next" and all files with an extension (e.g. favicon.ico) | ||
matcher: ['/((?!api|_next|.*\\..*).*)'], | ||
}; |