-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
35 lines (30 loc) · 1 KB
/
Copy pathproxy.ts
File metadata and controls
35 lines (30 loc) · 1 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
import { withAuth } from "next-auth/middleware";
import { NextResponse } from "next/server";
export default withAuth(
function proxy(req) {
const token = req.nextauth.token;
// 1. Check for banned status and redirect with a context parameter
if (token?.error === "BannedUser") {
const url = new URL("/", req.url);
url.searchParams.set("error", "banned");
return NextResponse.redirect(url);
}
// 2. Check for deleted status and redirect with a context parameter
if (token?.error === "DeletedUser") {
const url = new URL("/", req.url);
url.searchParams.set("error", "deleted");
return NextResponse.redirect(url);
}
// 3. Valid user, proceed normally
return NextResponse.next();
},
{
callbacks: {
// The authorized callback simply ensures a token exists before running the proxy function
authorized: ({ token }) => !!token,
},
},
);
export const config = {
matcher: ["/home", "/semester/:sem*", "/dashboard", "/query"],
};