最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sql - Why isn’t this (supabase) trigger working? - Stack Overflow

programmeradmin8浏览0评论

When I'm creating a user via the Supabase authentication system, everything goes well untill i try to create this trigger:

This is my public.users table:

id (uuid, primary key, default value: gen_random_uuid())
created_at (timestampz, default: now())
firstname (text, default NULL)
lastname (text, default NULL)
email (text, default NULL)
auth_id (uuid, foreign key (auth_id -> auth.users.id), default value auth.uid())

None of the columns are nullable!

RLS for this public.users table (for insert):

permissive, 
alter policy "Enable insert for authenticated users only"
on "public"."users"
to authenticated
with check (
  true
);

Function: handle_new_confirmed_user:

begin
  -- Insert a new row in public.users only if it doesn't exist
  insert into public.users (auth_id, firstname, lastname, email)
  values (new.id, new.raw_user_meta_data->>'firstName', new.raw_user_meta_data->>'lastName', new.email)
  on conflict (auth_id) do nothing; -- Prevents duplicate entries
  return new;
end;

trigger (on auth schema, table users): on_auth_user_confirmed:

enabled mode: always
condition: ((old.email_confirmed_at IS NULL) AND (new.email_confirmed_at IS NOT NULL))
function: handle_new_confirmed_user
events: after update
orientation: row

raw_user_meta_data upon creation:

{
  "sub": "4a78b921-e556-4f33-99fb-ac4a8217c9af",
  "email": "[email protected]",
  "lastName": "Doe",
  "firstName": "John",
  "email_verified": false,
  "phone_verified": false
}

I tried relaxing the RSL (did nothing), creating the user upon auth creation instead of after email confirmation (did nothing). I always get the error: http://localhost:3000/error?message=Error%20confirming%20user

The fault is certainly in the supabase backend and not in the code. Any help much appreciated!

发布评论

评论列表(0)

  1. 暂无评论