-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmiddleware.ts
More file actions
35 lines (29 loc) · 798 Bytes
/
Copy pathmiddleware.ts
File metadata and controls
35 lines (29 loc) · 798 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
35
import { NextRequest, NextResponse } from "next/server";
const PUBLIC_PATHS = [
"/login",
"/signup",
"/verify",
"/reset-password",
"/auth/callback",
];
export function middleware(request: NextRequest) {
const { pathname } = request.nextUrl;
if (
pathname.startsWith("/_next") ||
pathname.startsWith("/api") ||
pathname.startsWith("/uploads") ||
pathname === "/favicon.ico" ||
PUBLIC_PATHS.some((p) => pathname.startsWith(p))
) {
return NextResponse.next();
}
const token = request.cookies.get("access_token");
if (!token) {
const loginUrl = new URL("/login", request.url);
return NextResponse.redirect(loginUrl);
}
return NextResponse.next();
}
export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
};