Skip to content

Commit

Permalink
Merge pull request #254 from Kernel360/feature-middleware
Browse files Browse the repository at this point in the history
페이지 기능: middleware 설정
  • Loading branch information
bottlewook authored Mar 4, 2024
2 parents 7976868 + 8d10986 commit 86416b0
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/middleware.ts
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|.*\\..*).*)'],
};

0 comments on commit 86416b0

Please sign in to comment.