-
Notifications
You must be signed in to change notification settings - Fork 3
/
middleware.ts
35 lines (32 loc) · 1.22 KB
/
middleware.ts
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
28
29
30
31
32
33
34
35
import { NextRequest, NextResponse } from 'next/server';
import { cookies } from 'next/headers';
export function middleware(request: NextRequest) {
const accessToken = cookies().get('accessToken')?.value;
// const accessToken = request.cookies.get('accessToken')?.value; 랑 동일..!
// 채팅 리다리렉트
if (request.nextUrl.pathname.startsWith('/chat')) {
if (!accessToken) {
return NextResponse.redirect(new URL('/user-chat-login', request.url));
} else return NextResponse.next();
}
if (accessToken) {
if (request.nextUrl.pathname.startsWith('/login')) {
return NextResponse.redirect(new URL('/mypage', request.url));
}
} else if (!accessToken) {
if (request.nextUrl.pathname.startsWith('/mypage')) {
if (request.nextUrl.pathname === '/mypage/dashboard/terms') {
return NextResponse.next();
} else if (
request.nextUrl.pathname.startsWith('/mypage/dashboard/conditions')
) {
return NextResponse.next();
} else if (request.nextUrl.pathname === '/mypage/dashboard/privacy') {
return NextResponse.next();
} else {
return NextResponse.redirect(new URL('/login', request.url));
}
}
}
return NextResponse.next();
}