forked from GihoKo/taskify_team8
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
27 lines (21 loc) · 1.12 KB
/
middleware.ts
File metadata and controls
27 lines (21 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { cookies } from 'next/headers';
import { NextResponse } from 'next/server';
import { ACCESS_TOKEN } from '@constants/token';
import type { NextRequest } from 'next/server';
export function middleware(request: NextRequest) {
console.log('middleware가 시작되었습니다.');
const accessToken = cookies().get(ACCESS_TOKEN)?.value;
if (!accessToken) {
console.log('accessToken이 없습니다.');
// @see URL second argument https://nodejs.org/api/url.html#new-urlinput-base
// @see Conditional Statements https://nextjs.org/docs/app/building-your-application/routing/middleware#conditional-statements
const signPage = new URL('/signin', request.nextUrl.origin);
return NextResponse.redirect(signPage);
}
}
// Good to know: The matcher values need to be constants so they can be statically analyzed at build-time. Dynamic values such as variables will be ignored.
// @see https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher
// configured matchers: 부분 보면 쉽게 이해 가능
export const config = {
matcher: ['/dashboard/:dashboardId*', '/mydashboard', '/mypage'],
};