-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
36 lines (32 loc) · 894 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
35
36
// export { auth as middleware } from "@/auth";
import { auth } from "@/auth";
export default auth((req) => {
const { auth } = req;
const { pathname } = req.nextUrl;
// List of public pages that don't require authentication
const publicPages = [
"/",
"/login",
"/signup",
"/verify-email",
"/forgot-password",
"/reset-password",
];
const isPublicPage = publicPages.includes(pathname);
// If it's not a public page and user isn't authenticated
if (!auth && !isPublicPage) {
return Response.redirect(new URL("/login", req.url));
}
});
export const config = {
matcher: [
// "/((?!api|_next|.*\\..*).*)",
"/((?!api|_next/static|_next/image|favicon.ico).*)",
"/admin-dashboard",
"/company-dashboard",
"/student-dashboard",
"/admin-dashboard/:path*",
"/company-dashboard/:path*",
"/student-dashboard/:path*",
],
};