mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 06:15:39 -04:00
- Move /setup out of protected (pages) route group so it's accessible without auth (fixes fresh install redirect loop) - Redirect /login → /register when zero users exist - Add "Get Started" button on landing page for fresh installs - Hide register button/link when registration is closed - Add auth redirects: logged-in users on /login or /register → /dashboard - Convert register page to server component with server-side checks - Fix animation snap on auth form buttons (transition-all → scoped) - Update proxy middleware with /login and /register 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"]);
|
|
|
|
export function proxy(request: NextRequest) {
|
|
const sessionCookie = getSessionCookie(request);
|
|
const { pathname } = request.nextUrl;
|
|
|
|
if (pathname === "/") {
|
|
if (sessionCookie) {
|
|
return NextResponse.redirect(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*",
|
|
],
|
|
};
|