refactor: migrate authentication system and update Drizzle schema.

This commit is contained in:
2025-11-29 02:26:26 -05:00
parent c88e5d9d82
commit 3ebec7aa4a
36 changed files with 603 additions and 440 deletions
+52
View File
@@ -0,0 +1,52 @@
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export function proxy(request: NextRequest) {
const { pathname } = request.nextUrl;
// Define public routes that don't require authentication
const publicRoutes = ["/", "/auth/signin", "/auth/register"];
// Define API routes that should be handled separately
const apiRoutes = ["/api/auth", "/api/trpc"];
// Allow API routes to pass through
if (apiRoutes.some((route) => pathname.startsWith(route))) {
return NextResponse.next();
}
// Allow public routes for everyone
if (publicRoutes.includes(pathname)) {
return NextResponse.next();
}
// Check for session token in cookies (Better Auth cookie names)
const sessionToken =
request.cookies.get("better-auth.session_token")?.value ??
request.cookies.get("__Secure-better-auth.session_token")?.value;
// If no session token, redirect to sign-in
if (!sessionToken) {
const signInUrl = new URL("/auth/signin", request.url);
signInUrl.searchParams.set("callbackUrl", request.url);
return NextResponse.redirect(signInUrl);
}
// Session token exists, allow the request to proceed
// The actual pages will validate the token properly
return NextResponse.next();
}
export const config = {
matcher: [
/*
* Match all request paths except for the ones starting with:
* - api/auth (Auth.js API routes)
* - _next/static (static files)
* - _next/image (image optimization files)
* - favicon.ico (favicon file)
* - public folder files
*/
"/((?!api/auth|_next/static|_next/image|favicon.ico|.*\\.png$|.*\\.jpg$|.*\\.jpeg$|.*\\.gif$|.*\\.svg$).*)",
],
};