-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmiddleware.js
More file actions
35 lines (27 loc) · 721 Bytes
/
middleware.js
File metadata and controls
35 lines (27 loc) · 721 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
30
31
32
33
34
35
import { NextResponse } from 'next/server';
export function middleware(req) {
const userAccessing = req.nextUrl.pathname;
const cookie = req.cookies.get('userSession');
const hasSession = !!cookie;
const publicRoutes = ['/auth'];
const isPublic = publicRoutes.some((path) =>
userAccessing.startsWith(path)
);
if (!hasSession && !isPublic) {
return NextResponse.redirect(new URL('/auth', req.url));
}
if(isPublic && hasSession){
return NextResponse.redirect(new URL('/', req.url));
}
return NextResponse.next();
}
export const config = {
matcher: [
'/dashboard/:path*',
'/billing',
'/settings',
'/all-interview',
'/scheduled-interview',
'/auth',
],
};