New User Signup Failing with RLS Error Despite Correct Policy

Hello everyone,
I'm facing a critical issue where new user signups are failing. The user is successfully created in auth.users (I receive the confirmation email), but the trigger to insert a corresponding row into public.user_profiles fails with a 401 Unauthorized error:
new row violates row-level security policy for table "user_profiles"

The problem is that my RLS policy for this action appears to be configured perfectly. I've verified using pg_policies that my single, active INSERT policy is:
  • Role: authenticated
  • WITH CHECK expression: (auth.uid() = id)
    The most critical diagnostic step I've taken is to temporarily disable RLS on the user_profiles table. When I do this, the 401 error disappears, which proves that the RLS system itself is the source of the block, even though the policy seems correct.
    I have already fixed other potential issues like NOT NULL constraints and cleaned up orphan rows from previous failed attempts. After re-enabling the correct RLS policy, the 401 error returns.
    In summary: a perfectly configured RLS policy is not being respected by the database, and I am completely stuck. Has anyone encountered an issue like this? It feels like a project-specific bug.
    Any help or ideas would be greatly appreciated. Thank you!
Was this page helpful?