mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-08-29 02:45:39 -04:00
Refactor auth session handling and server actions across app
- Overhaul `lib/auth/server.ts` and `lib/auth/session.ts`; update all API routes and server actions to use the revised session pattern - Refactor server actions (settings, titles, watchlist, setup) for consistency with new auth layer - Extract `SetupForm` into its own client component with `useActionState`, animated steps, and copyable env snippets - Move landing page redirect logic into `app/page.tsx`; slim down `LandingPage` component - Add `proxy.ts` for local dev proxying - Minor cleanup to `NavBar`, `MobileTabBar`, and `TitleCard`
This commit is contained in:
@@ -4,19 +4,21 @@ 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;
|
||||
|
||||
// this is ONLY for optimistic redirects, it does not provide any actual security
|
||||
const sessionCookie = getSessionCookie(request);
|
||||
|
||||
// Special case for root: becomes dashboard if logged in, landing page if not
|
||||
if (pathname === "/") {
|
||||
if (sessionCookie) {
|
||||
return NextResponse.rewrite(new URL("/dashboard", request.url));
|
||||
}
|
||||
return NextResponse.next();
|
||||
return sessionCookie
|
||||
? NextResponse.rewrite(new URL("/dashboard", request.url))
|
||||
: NextResponse.next();
|
||||
}
|
||||
|
||||
// Logged-in users on auth pages → dashboard
|
||||
if (authRoutes.has(pathname) && sessionCookie) {
|
||||
return NextResponse.redirect(new URL("/dashboard", request.url));
|
||||
return NextResponse.redirect(new URL("/", request.url));
|
||||
}
|
||||
|
||||
// Unauthenticated users on protected pages → login
|
||||
@@ -29,13 +31,6 @@ export function proxy(request: NextRequest) {
|
||||
|
||||
export const config = {
|
||||
matcher: [
|
||||
"/",
|
||||
"/login",
|
||||
"/register",
|
||||
"/dashboard",
|
||||
"/explore",
|
||||
"/settings",
|
||||
"/setup",
|
||||
"/titles/:path*",
|
||||
"/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)",
|
||||
],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user