mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 05:05:38 -04:00
The proxy treated /setup as a protected route, redirecting unauthenticated users to /login. This made first-run TMDB onboarding unreachable since no users exist yet. Add /setup to public auth routes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { getSessionCookie } from "better-auth/cookies";
|
|
import { type NextRequest, NextResponse } from "next/server";
|
|
|
|
const authRoutes = new Set(["/login", "/register", "/setup"]);
|
|
|
|
export function proxy(request: NextRequest) {
|
|
const sessionCookie = getSessionCookie(request);
|
|
const { pathname } = request.nextUrl;
|
|
|
|
if (pathname === "/") {
|
|
if (sessionCookie) {
|
|
return NextResponse.rewrite(new URL("/dashboard", request.url));
|
|
}
|
|
return NextResponse.next();
|
|
}
|
|
|
|
// Logged-in users on auth pages → dashboard
|
|
if (authRoutes.has(pathname) && sessionCookie) {
|
|
return NextResponse.redirect(new URL("/dashboard", request.url));
|
|
}
|
|
|
|
// Unauthenticated users on protected pages → login
|
|
if (!authRoutes.has(pathname) && !sessionCookie) {
|
|
return NextResponse.redirect(new URL("/login", request.url));
|
|
}
|
|
|
|
return NextResponse.next();
|
|
}
|
|
|
|
export const config = {
|
|
matcher: [
|
|
"/",
|
|
"/login",
|
|
"/register",
|
|
"/dashboard",
|
|
"/explore",
|
|
"/settings",
|
|
"/setup",
|
|
"/titles/:path*",
|
|
],
|
|
};
|