mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 01:35:39 -04:00
Improve fresh install flow and auth page routing
- 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>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
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;
|
||||
@@ -12,7 +14,13 @@ export function proxy(request: NextRequest) {
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
if (!sessionCookie) {
|
||||
// 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));
|
||||
}
|
||||
|
||||
@@ -22,6 +30,8 @@ export function proxy(request: NextRequest) {
|
||||
export const config = {
|
||||
matcher: [
|
||||
"/",
|
||||
"/login",
|
||||
"/register",
|
||||
"/dashboard",
|
||||
"/explore",
|
||||
"/settings",
|
||||
|
||||
Reference in New Issue
Block a user