fix: resolve infinite recursion in admin_users RLS policy
The admin_users policy was checking if user is admin by querying the same table, causing infinite recursion. Changed to allow users to view their own admin record directly using auth.uid() = user_id. This fixes the error: 'infinite recursion detected in policy for relation admin_users'
This commit is contained in:
48
src/app/api/debug-admin/route.ts
Normal file
48
src/app/api/debug-admin/route.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { createServerComponentClient } from '@supabase/auth-helpers-nextjs';
|
||||
import { cookies } from 'next/headers';
|
||||
import { NextResponse } from 'next/server';
|
||||
|
||||
export async function GET() {
|
||||
const supabase = createServerComponentClient({ cookies });
|
||||
|
||||
// Get current user
|
||||
const { data: { user }, error: userError } = await supabase.auth.getUser();
|
||||
|
||||
if (userError || !user) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
error: 'Not authenticated',
|
||||
userError: userError?.message
|
||||
});
|
||||
}
|
||||
|
||||
// Check admin_users table
|
||||
const { data: adminData, error: adminError } = await supabase
|
||||
.from('admin_users')
|
||||
.select('*')
|
||||
.eq('user_id', user.id)
|
||||
.single();
|
||||
|
||||
// Get all admin users (for debugging)
|
||||
const { data: allAdmins, error: allAdminsError } = await supabase
|
||||
.from('admin_users')
|
||||
.select('*');
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
currentUser: {
|
||||
id: user.id,
|
||||
email: user.email
|
||||
},
|
||||
adminCheck: {
|
||||
data: adminData,
|
||||
error: adminError?.message,
|
||||
isAdmin: !!adminData
|
||||
},
|
||||
allAdmins: {
|
||||
data: allAdmins,
|
||||
error: allAdminsError?.message,
|
||||
count: allAdmins?.length || 0
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user