-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
35 lines (29 loc) · 862 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
28
29
30
31
32
33
34
35
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function middleware(request: NextRequest) {
const path = request.nextUrl.pathname;
const isPublicPath =
path === "/signIn" ||
path === "/signUp" ||
path === "/forgot-password" ||
path === "/contact";
const isGeneratePath = path === "/generate";
const token = request.cookies.get("token")?.value || "";
if (isGeneratePath && !token) {
return NextResponse.redirect(new URL("/signIn", request.nextUrl));
}
if (!isPublicPath && !token) {
return NextResponse.redirect(new URL("/signIn", request.nextUrl));
}
}
// See "Matching Paths" below to learn more
export const config = {
matcher: [
"/",
"/signIn",
"/signUp",
"/forgot-password",
"/generate",
"/contact", // Corrected the path here
],
};