Files
loki/src/proxy.ts
T
g-butandClaude Sonnet 4.6 d57e520ea0 fix(build): remove middleware.ts — proxy.ts already handles auth routing
Next.js/Vercel rejects having both middleware.ts and proxy.ts. The existing
proxy.ts already protected all app routes and handles the onboarding redirect.
Extended it with /sign-out and /thoughts as public paths.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-14 15:52:25 +02:00

41 lines
1.2 KiB
TypeScript

import { auth } from "@/auth";
import { NextResponse } from "next/server";
const PUBLIC_PATHS = new Set(["/", "/sign-in", "/sign-out", "/setup"]);
export default auth((req) => {
const { pathname, search } = req.nextUrl;
// Static/API paths — let them through (API routes handle their own auth)
if (
pathname.startsWith("/_next") ||
pathname.startsWith("/api/") ||
pathname === "/favicon.ico"
) {
return NextResponse.next();
}
// Public pages, invite registration, beacon popup, and public essays — always accessible
if (PUBLIC_PATHS.has(pathname) || pathname.startsWith("/invite/") || pathname.startsWith("/beacon/") || pathname.startsWith("/thoughts")) {
return NextResponse.next();
}
// Unauthenticated → sign-in with return URL
if (!req.auth) {
const signIn = new URL("/sign-in", req.url);
signIn.searchParams.set("callbackUrl", `${pathname}${search}`);
return NextResponse.redirect(signIn);
}
// Authenticated but no username yet → onboarding
if (!req.auth.user?.username && pathname !== "/onboarding") {
return NextResponse.redirect(new URL("/onboarding", req.url));
}
return NextResponse.next();
});
export const config = {
matcher: ["/((?!_next/static|_next/image|favicon.ico).*)"],
};