-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathproxy.ts
More file actions
27 lines (24 loc) · 981 Bytes
/
proxy.ts
File metadata and controls
27 lines (24 loc) · 981 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
import { get } from "@vercel/edge-config";
import { NextResponse } from "next/server";
import { supabaseMiddleware } from "./lib/supabase";
export const proxy = supabaseMiddleware(async (user, request) => {
const maintenance = await get("maintenance");
if (maintenance) {
request.nextUrl.pathname = "/maintenance";
// Rewrite to the url
return NextResponse.rewrite(request.nextUrl);
}
if (user == null) {
// no user, potentially respond by redirecting the user to the login page
const url = request.nextUrl.clone();
const returnUrl = request.nextUrl.pathname + request.nextUrl.search;
url.pathname = "/login";
url.searchParams.set("returnUrl", returnUrl);
return NextResponse.redirect(url);
}
});
export const config = {
matcher: [
"/((?!_next/static|_next/image|.well-known|webhooks|legal|login|signup|join|pricing|password_reset|auth|api/vector-stores/cron|api/apps|agent-api|robots\\.txt|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)",
],
};