-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmiddleware.ts
More file actions
25 lines (18 loc) · 855 Bytes
/
Copy pathmiddleware.ts
File metadata and controls
25 lines (18 loc) · 855 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
import { NextResponse } from "next/server";
import { getToken } from "next-auth/jwt";
import type { NextRequest } from "next/server";
export async function middleware(req: NextRequest) {
const token = await getToken({ req, secret: process.env.NEXTAUTH_SECRET });
if (!token) return NextResponse.next();
const isOnboardingPage = req.nextUrl.pathname === "/onboarding";
const isDashboardPage = req.nextUrl.pathname.startsWith("/dashboard");
// Comment out this redirection check temporarily
// if (!token.isOnboarded && isDashboardPage) {
// return NextResponse.redirect(new URL("/onboarding", req.url));
// }
if (token.isOnboarded && isOnboardingPage) {
return NextResponse.redirect(new URL("/dashboard", req.url));
}
return NextResponse.next();
}
export const config = { matcher: ["/dashboard/:path*", "/onboarding"] };