Skip to content
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

페이지 기능: middleware 설정 #254

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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|.*\\..*).*)'],
};
Loading