-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathproxy.ts
More file actions
25 lines (20 loc) · 773 Bytes
/
proxy.ts
File metadata and controls
25 lines (20 loc) · 773 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 { auth } from "@/lib/auth";
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export async function proxy(req: NextRequest) {
const isAuthPage = req.nextUrl.pathname.startsWith("/auth");
const isApiRoute = req.nextUrl.pathname.startsWith("/api");
// Allow API routes and auth pages through without auth check
if (isApiRoute || isAuthPage) {
return NextResponse.next();
}
// For all other routes, check authentication
const session = await auth();
if (!session) {
return NextResponse.redirect(new URL("/auth/signin", req.url));
}
return NextResponse.next();
}
export const config = {
matcher: ["/((?!api|_next/static|_next/image|favicon.ico|icon.png).*)"],
};