-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.ts
More file actions
29 lines (23 loc) · 847 Bytes
/
middleware.ts
File metadata and controls
29 lines (23 loc) · 847 Bytes
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
import type { NextRequest } from 'next/server';
import { NextResponse } from 'next/server';
import { ROUTES } from '@constants/routes';
import { STORAGE_KEY } from '@models/storage';
export const middleware = async (request: NextRequest) => {
const refreshToken = request.cookies.get(STORAGE_KEY.REFRESH_TOKEN);
if (request.nextUrl.pathname.startsWith('/terms')) return;
if (refreshToken?.value && request.nextUrl.pathname === '/') {
return NextResponse.redirect(
new URL(`${ROUTES.MAIN}?tab=write`, request.url),
);
}
if (
!refreshToken &&
request.nextUrl.pathname !== '/' &&
!request.nextUrl.pathname.startsWith('/redirect')
) {
return NextResponse.redirect(new URL(ROUTES.LANDING, request.url));
}
};
export const config = {
matcher: ['/((?!api|_next/static|_next/image|favicon.ico).*)'],
};