chore(middleware): only enforce admin gate in production to simplify local dev with Better Auth cookie cache

This commit is contained in:
Esdras Renan 2025-10-10 09:56:42 -03:00
parent 2877f22dfb
commit 8fb2e4caaf

View file

@ -24,7 +24,13 @@ export async function middleware(request: NextRequest) {
const role = (session.user as { role?: string })?.role?.toLowerCase() ?? "agent"
const isAdmin = role === "admin"
if (!isAdmin && ADMIN_ONLY_PATHS.some((pattern) => pattern.test(pathname))) {
// Em desenvolvimento, evitamos bloquear rotas admin por possíveis diferenças
// de cache de cookie/sessão entre dev server e middleware. Em produção, aplica o gate.
if (
process.env.NODE_ENV === "production" &&
!isAdmin &&
ADMIN_ONLY_PATHS.some((pattern) => pattern.test(pathname))
) {
return NextResponse.redirect(new URL(APP_HOME, request.url))
}