refactor: migrate from ESLint to Biome and extract SQL queries to data.ts
- Replace ESLint with Biome for linting and formatting - Configure Biome with tabs, double quotes, and organized imports - Move all SQL/Drizzle queries from page.tsx files to data.ts files - Create new data.ts files for: ajustes, dashboard, relatorios/categorias - Update existing data.ts files: extrato, fatura (add lancamentos queries) - Remove all drizzle-orm imports from page.tsx files - Update README.md with new tooling info Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
94
proxy.ts
94
proxy.ts
@@ -1,66 +1,66 @@
|
||||
import { type NextRequest, NextResponse } from "next/server";
|
||||
import { auth } from "@/lib/auth/config";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
// Rotas protegidas que requerem autenticação
|
||||
const PROTECTED_ROUTES = [
|
||||
"/ajustes",
|
||||
"/anotacoes",
|
||||
"/calendario",
|
||||
"/cartoes",
|
||||
"/categorias",
|
||||
"/contas",
|
||||
"/dashboard",
|
||||
"/insights",
|
||||
"/lancamentos",
|
||||
"/orcamentos",
|
||||
"/pagadores",
|
||||
"/ajustes",
|
||||
"/anotacoes",
|
||||
"/calendario",
|
||||
"/cartoes",
|
||||
"/categorias",
|
||||
"/contas",
|
||||
"/dashboard",
|
||||
"/insights",
|
||||
"/lancamentos",
|
||||
"/orcamentos",
|
||||
"/pagadores",
|
||||
];
|
||||
|
||||
// Rotas públicas (não requerem autenticação)
|
||||
const PUBLIC_AUTH_ROUTES = ["/login", "/signup"];
|
||||
|
||||
export default async function proxy(request: NextRequest) {
|
||||
const { pathname } = request.nextUrl;
|
||||
const { pathname } = request.nextUrl;
|
||||
|
||||
// Validate actual session, not just cookie existence
|
||||
const session = await auth.api.getSession({
|
||||
headers: request.headers,
|
||||
});
|
||||
// Validate actual session, not just cookie existence
|
||||
const session = await auth.api.getSession({
|
||||
headers: request.headers,
|
||||
});
|
||||
|
||||
const isAuthenticated = !!session?.user;
|
||||
const isAuthenticated = !!session?.user;
|
||||
|
||||
// Redirect authenticated users away from login/signup pages
|
||||
if (isAuthenticated && PUBLIC_AUTH_ROUTES.includes(pathname)) {
|
||||
return NextResponse.redirect(new URL("/dashboard", request.url));
|
||||
}
|
||||
// Redirect authenticated users away from login/signup pages
|
||||
if (isAuthenticated && PUBLIC_AUTH_ROUTES.includes(pathname)) {
|
||||
return NextResponse.redirect(new URL("/dashboard", request.url));
|
||||
}
|
||||
|
||||
// Redirect unauthenticated users trying to access protected routes
|
||||
const isProtectedRoute = PROTECTED_ROUTES.some((route) =>
|
||||
pathname.startsWith(route)
|
||||
);
|
||||
// Redirect unauthenticated users trying to access protected routes
|
||||
const isProtectedRoute = PROTECTED_ROUTES.some((route) =>
|
||||
pathname.startsWith(route),
|
||||
);
|
||||
|
||||
if (!isAuthenticated && isProtectedRoute) {
|
||||
return NextResponse.redirect(new URL("/login", request.url));
|
||||
}
|
||||
if (!isAuthenticated && isProtectedRoute) {
|
||||
return NextResponse.redirect(new URL("/login", request.url));
|
||||
}
|
||||
|
||||
return NextResponse.next();
|
||||
return NextResponse.next();
|
||||
}
|
||||
|
||||
export const config = {
|
||||
// Apply middleware to protected and auth routes
|
||||
matcher: [
|
||||
"/ajustes/:path*",
|
||||
"/anotacoes/:path*",
|
||||
"/calendario/:path*",
|
||||
"/cartoes/:path*",
|
||||
"/categorias/:path*",
|
||||
"/contas/:path*",
|
||||
"/dashboard/:path*",
|
||||
"/insights/:path*",
|
||||
"/lancamentos/:path*",
|
||||
"/orcamentos/:path*",
|
||||
"/pagadores/:path*",
|
||||
"/login",
|
||||
"/signup",
|
||||
],
|
||||
};
|
||||
// Apply middleware to protected and auth routes
|
||||
matcher: [
|
||||
"/ajustes/:path*",
|
||||
"/anotacoes/:path*",
|
||||
"/calendario/:path*",
|
||||
"/cartoes/:path*",
|
||||
"/categorias/:path*",
|
||||
"/contas/:path*",
|
||||
"/dashboard/:path*",
|
||||
"/insights/:path*",
|
||||
"/lancamentos/:path*",
|
||||
"/orcamentos/:path*",
|
||||
"/pagadores/:path*",
|
||||
"/login",
|
||||
"/signup",
|
||||
],
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user