-
Notifications
You must be signed in to change notification settings - Fork 0
/
middleware.ts
27 lines (20 loc) · 932 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
import { getToken } from "next-auth/jwt";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export async function middleware(req: NextRequest) {
const token = await getToken({ req, secret: process.env.NEXTAUTH_SECRET });
const { pathname } = req.nextUrl;
// If no token exists and the user is trying to access a protected route, redirect to the home page.
//outcommented for now...vercel site issue..
/* if (!token && pathname !== "/") {
console.log("No token, redirecting to home");
return NextResponse.redirect(new URL("/", req.url));
} */
// Proceed with the request if authenticated or accessing home page. (outcommented code above, debug issue...vercel..)
return NextResponse.next();
}
// Configuring the matcher to protect specific routes
// be sure to update if adding new pages
export const config = {
matcher: ["/challenge/:path*", "/profile"],
};