-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
34 lines (27 loc) · 932 Bytes
/
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
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export async function middleware(request: NextRequest) {
const accessToken = request.cookies.has('AccessToken')
const refreshToken = request.cookies.has('RefreshToken')
if (accessToken && refreshToken) return NextResponse.next()
if (!accessToken && refreshToken) {
const response = await fetch(
'https://api.travelersenior.site/api/token/reissue',
{
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${request.cookies.get('RefreshToken')}`,
},
},
)
console.log(response)
return NextResponse.next()
}
if (
request.nextUrl.pathname.startsWith('/quit') ||
request.nextUrl.pathname.startsWith('/my-page')
)
return NextResponse.redirect(new URL('/login', request.url))
return NextResponse.next()
}