-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.ts
54 lines (46 loc) · 1.04 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export async function middleware(request: NextRequest) {
const url = request.nextUrl.clone();
const token = request.cookies.get('token');
// login
if (url.pathname === '/superadmin/login') {
if (token) {
url.pathname = '/superadmin'
return NextResponse.redirect(url);
} else {
return NextResponse.next();
}
}
// superadmin
if (url.pathname.includes('/superadmin')) {
if (token) {
return NextResponse.next();
} else {
url.pathname = '/'
return NextResponse.redirect(url);
}
}
url.pathname = `client${url.pathname}`;
return NextResponse.rewrite(url);
}
export const config = {
matcher: [
// public routes
'/',
'/blogs',
'/listing',
'/customize-trip',
'/blogs/detail',
'/contact',
'/register',
'/destinations/:path',
'/blogs',
'/blogs/:path',
'/our_team',
'/videos',
// admin routes
'/superadmin/login',
'/superadmin',
]
}