-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy.ts
More file actions
32 lines (26 loc) · 875 Bytes
/
proxy.ts
File metadata and controls
32 lines (26 loc) · 875 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
import { type NextRequest, NextResponse } from "next/server";
import { updateSession } from "@/utils/supabase/middleware";
function isPublicPath(pathname: string) {
if (pathname === "/login") return true;
if (pathname.startsWith("/auth/")) return true;
if (pathname === "/") return true;
return false;
}
export async function proxy(request: NextRequest) {
const { response, user } = await updateSession(request);
if (isPublicPath(request.nextUrl.pathname)) {
return response;
}
if (!user) {
const url = request.nextUrl.clone();
url.pathname = "/login";
url.searchParams.set("next", `${request.nextUrl.pathname}${request.nextUrl.search}`);
return NextResponse.redirect(url);
}
return response;
}
export const config = {
matcher: [
"/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
],
};