INNER CODE UNIT · TypeScript
middleware
Ammaar-Alam/minebench · middleware.ts:246
export async function middleware(req: NextRequest) {
const canonicalRedirect = maybeRedirectToCanonicalHost(req);
if (canonicalRedirect) return canonicalRedirect;
const modelSlugRedirect = maybeRedirectToCanonicalModelSlug(req);
if (modelSlugRedirect) return modelSlugRedirect;
const { pathname } = req.nextUrl;
const isLabApi = pathname.startsWith("/api/lab/");
const isGalleryAccountApi = hasSupabaseAuthCookie(req.headers.get("cookie")) && (
pathname.startsWith("/api/generations") || pathname.startsWith("/api/gallery")
);
const refreshesSupabase =
pathname.startsWith("/lab") ||
isLabApi ||
pathname === "/sandbox" ||
pathname.startsWith("/gallery") ||
pathname.startsWith("/admin/gallery") ||