-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.js
More file actions
34 lines (30 loc) · 848 Bytes
/
proxy.js
File metadata and controls
34 lines (30 loc) · 848 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
import { withAuth } from "next-auth/middleware";
import { NextResponse } from "next/server";
export default withAuth(
function middleware(req) {
const token = req.nextauth.token;
const pathname = req.nextUrl.pathname;
// If user is not email verified and trying to access dashboard
// Redirect them to verify page
if (pathname.startsWith("/dashboard") && token && !token.emailVerified) {
return NextResponse.redirect(new URL("/register/verify", req.url));
}
return NextResponse.next();
},
{
pages: {
signIn: "/login",
},
}
);
export const config = {
matcher: [
"/dashboard/:path*",
"/admin/:path*",
"/api/products/:path*",
"/api/stock-adjustments/:path*",
"/api/settings/:path*",
"/api/auth/users/:path*",
"/api/auth/registerBusiness/verify/:path*",
],
};