feat: adds signup disabling middleware

This commit is contained in:
zomars
2024-02-03 14:47:51 -07:00
parent eeb0fc795d
commit af1382c5ba
+9
View File
@@ -60,6 +60,14 @@ const middleware = async (req: NextRequest): Promise<NextResponse<unknown>> => {
requestHeaders.set("x-cal-timezone", req.headers.get("x-vercel-ip-timezone") ?? "");
}
if (url.pathname.startsWith("/api/auth/signup")) {
const isSignupDisabled = await get<boolean>("isSignupDisabled");
// If is in maintenance mode, point the url pathname to the maintenance page
if (isSignupDisabled) {
return NextResponse.json({ error: "Signup is disabled" }, { status: 503 });
}
}
if (url.pathname.startsWith("/auth/login") || url.pathname.startsWith("/login")) {
// Use this header to actually enforce CSP, otherwise it is running in Report Only mode on all pages.
requestHeaders.set("x-csp-enforce", "true");
@@ -114,6 +122,7 @@ export const config = {
// https://github.com/vercel/next.js/discussions/42458
matcher: [
"/:path*/embed",
"/api/auth/signup",
"/api/trpc/:path*",
"/login",
"/auth/login",