fixed authcontext for sign up, added 404 and middleware for prod readiness
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
// middleware.ts
|
||||
import { NextResponse } from "next/server";
|
||||
import type { NextRequest } from "next/server";
|
||||
|
||||
const LAUNCH_ONLY_ROOT = process.env.NEXT_PUBLIC_LAUNCH_ONLY_ROOT === "true";
|
||||
|
||||
// Allow only root + essential static files
|
||||
const ALLOW = new Set([
|
||||
"/",
|
||||
"/favicon.ico",
|
||||
"/robots.txt",
|
||||
"/sitemap.xml",
|
||||
]);
|
||||
|
||||
export function middleware(req: NextRequest) {
|
||||
if (!LAUNCH_ONLY_ROOT) return NextResponse.next();
|
||||
|
||||
const { pathname } = req.nextUrl;
|
||||
|
||||
// Always allow Next internals + static assets
|
||||
if (
|
||||
pathname.startsWith("/_next") ||
|
||||
pathname.startsWith("/assets") ||
|
||||
pathname.startsWith("/images")
|
||||
) {
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
// Allow the root + a few public files
|
||||
if (ALLOW.has(pathname)) return NextResponse.next();
|
||||
|
||||
// Everything else: hide it
|
||||
return NextResponse.rewrite(new URL("/404", req.url)); // or redirect to "/"
|
||||
}
|
||||
|
||||
export const config = {
|
||||
matcher: ["/:path*"],
|
||||
};
|
||||
Reference in New Issue
Block a user