This repository was archived by the owner on Dec 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmiddleware.ts
More file actions
58 lines (50 loc) Β· 2.09 KB
/
Copy pathmiddleware.ts
File metadata and controls
58 lines (50 loc) Β· 2.09 KB
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
55
56
57
58
import { NextResponse } from "next/server";
import { auth } from "./auth";
export default auth(async (req, ctx) => {
if(!req.auth?.user?.email && !req.nextUrl.pathname.toLowerCase().startsWith("/adminlogin")) {
return NextResponse.redirect(req.nextUrl.origin + "/AdminLogin");
}
return NextResponse.next();
});
// export default auth(async (req, ctx) => {
// const publicPages = ["/adminlogin"];
// if (req.auth?.user?.email) {
// if (publicPages.includes(req.nextUrl.pathname.toLowerCase())) {
// const adminCheckResponse = await fetch(req.nextUrl.origin + "/api/isAdmin", {
// body: JSON.stringify({ email: req.auth.user.email }),
// method: "POST"
// });
// const adminData = await adminCheckResponse.json();
// if (adminData.isAdmin) {
// return NextResponse.redirect(req.nextUrl.origin + '/AdminPortal');
// } else {
// return NextResponse.redirect(req.nextUrl.origin + '/Participants');
// }
// }
// const adminProtected = ["/adminportal", "/eventscrud", "/participants"];
// if (adminProtected.includes(req.nextUrl.pathname.toLowerCase())) {
// const adminCheckResponse = await fetch(req.nextUrl.origin + "/api/isAdmin", {
// body: JSON.stringify({ email: req.auth.user.email||"" }),
// method: "POST"
// });
// const adminData = await adminCheckResponse.json();
// if (!adminData.isAdmin) {
// return NextResponse.redirect(req.nextUrl.origin + '/AdminLogin');
// }
// }
// return NextResponse.next();
// } else if (!publicPages.includes(req.nextUrl.pathname.toLowerCase())) {
// return NextResponse.redirect(req.nextUrl.origin + '/AdminLogin');
// }
// });
export const config = {
matcher: [
'/AdminLogin',
'/AdminPortal',
'/EventsCRUD',
'/Participants',
'/Participants/:id',
"/EventStatistics",
"/CollegeStatistics",
]
}