forked from team-acode/sniff-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
31 lines (27 loc) · 848 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
import { NextResponse } from 'next/server';
import type { NextRequest } from 'next/server';
import { getSession } from './utils/auth';
export function middleware(request: NextRequest) {
const userInfo = getSession();
const { pathname, searchParams } = request.nextUrl;
if (pathname === '/login' && !searchParams.get('invalid') && userInfo)
return NextResponse.redirect(new URL('/', request.url));
if (
(pathname === '/welcome' ||
pathname.includes('/mypage') ||
// pathname.includes('/find-taste') ||
pathname.includes('/reviews')) &&
!userInfo
)
return NextResponse.redirect(new URL('/login', request.url));
return NextResponse.next();
}
export const config = {
matcher: [
'/login',
'/welcome',
'/mypage/:path',
// '/find-taste/:path',
'/perfumes/:path/reviews/new',
],
};