chore(middleware): only enforce admin gate in production to simplify local dev with Better Auth cookie cache
This commit is contained in:
parent
2877f22dfb
commit
8fb2e4caaf
1 changed files with 7 additions and 1 deletions
|
|
@ -24,7 +24,13 @@ export async function middleware(request: NextRequest) {
|
||||||
const role = (session.user as { role?: string })?.role?.toLowerCase() ?? "agent"
|
const role = (session.user as { role?: string })?.role?.toLowerCase() ?? "agent"
|
||||||
|
|
||||||
const isAdmin = role === "admin"
|
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))
|
return NextResponse.redirect(new URL(APP_HOME, request.url))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue