fix(middleware): exclude /api/ routes from role-prefix guard
API routes were being redirected for non-admin roles (e.g. capa_owner calling PATCH /api/capa/[id] got redirected to /capa-owner, breaking all API calls from role-restricted users). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WMymkhHZiaYZtUeH9MEHZQ
This commit is contained in:
+1
-1
@@ -49,7 +49,7 @@ export async function middleware(request: NextRequest) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user && !isPublicRoute && !isSharedRoute && pathname !== '/') {
|
if (user && !isPublicRoute && !isSharedRoute && !pathname.startsWith('/api/') && pathname !== '/') {
|
||||||
const { data: profile } = await supabase.from('users').select('role').eq('id', user.id).single()
|
const { data: profile } = await supabase.from('users').select('role').eq('id', user.id).single()
|
||||||
const role = profile?.role
|
const role = profile?.role
|
||||||
if (isValidRole(role) && role !== 'admin') {
|
if (isValidRole(role) && role !== 'admin') {
|
||||||
|
|||||||
Reference in New Issue
Block a user