-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmiddleware.ts
31 lines (26 loc) · 845 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
import { NextRequest, NextResponse } from "next/server";
export default async function middleware(req: NextRequest) {
const { nextUrl } = req;
const sessionToken = req.cookies.get("sessionToken");
if (nextUrl.pathname === "/auth/login") {
return NextResponse.next();
}
if (nextUrl.pathname.startsWith("/chat")) {
if (!sessionToken) {
return NextResponse.redirect(new URL("/auth/login", nextUrl));
}
return NextResponse.next();
}
return NextResponse.next();
}
export const config = {
matcher: [
"/",
"/explore",
"/my-packs/:path*",
"/payments",
"/chat/:path*",
"/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)",
"/(api|trpc)(.*)",
],
};