-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
29 lines (25 loc) · 846 Bytes
/
Copy pathproxy.ts
File metadata and controls
29 lines (25 loc) · 846 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
import { withAuth } from "next-auth/middleware";
import { NextResponse } from "next/server";
export default withAuth(
function middleware() {
return NextResponse.next();
},
{
callbacks: {
authorized: ({ token }) => {
// 1. If there's no token, they aren't logged in. Block them.
if (!token) return false;
// 2. If the token has the "BannedUser" or "DeletedUser" flag we set in route.ts,
// block them immediately. NextAuth will auto-redirect them to the sign-in page.
if (token.error === "BannedUser" || token.error === "DeletedUser") {
return false;
}
// 3. Otherwise, they are a valid, active user. Let them through.
return true;
},
},
},
);
export const config = {
matcher: ["/home", "/semester/:sem*", "/dashboard", "/query"],
};