Fixed supabase trigger
HTML-код
- Опубликовано: 2 окт 2023
- In this video I am going to show you how to fix create supabase trigger from auth.users table.
sql:
- create trigger: create trigger trigger_name after insert on auth.users for each row execute function function_name();
- delete trigger: drop trigger if exists trigger_name on auth.users;
Support the channel : 🙏🌸
- donate 🌻: / dailywebcoding
Follow me: 👇
- Discord: / discord
- Github: github.com/Chensokheng
Thank you so much for the quick work around on this.
Works a treat, great channel and please keep up the amazing work. Thanks Mark
Thank you so much! I was stuck at making trigger on auth table. Your video helps me a lot!
Thanks for the workaround! Worked like a charm.
Exactly what I needed! Thank you so much!
thank you for the workaround 🙌 keep going with great the Supabase contents.
Thank you! Will do!
Thank you so much for your tutorial! it is really helpful!
thanks man this helped me, straight to the point
This was clutch, thank you!
Thanks mate! Very nice video, appreciate it.
Great content man! Super useful 🙏
Glad it was helpful!
Thanks for this!
Thank you so much!
Really appreciated!
That solved it! Thank you!
Really nice, thank you.
thank you for this
Thanks it really helped
Thanks a lot
thanks you alot broo
ty 💋
Where is the create_user_on_signup function definition code??
you have to create it, goto Database, click functions and create one, here is an example
begin
insert into public.user (id, name, email)
values (new.id, new.raw_user_meta_data ->> 'name', new.email);
return new;
end;
thanks a lot!
You're welcome!
you the best
where can I find function that you used?
bro, just make it??
Great, but you only needed 2 minutes
i am getting this error while sign up AuthApiError: duplicate key value violates unique constraint "user_pkey" as i am created trigger from sql editor
I am stuck, supabase is not recognising the function i have created, is it security definer or invoker in advanced settings.
Why did they take it out in the first place? Does anyone know?
Could you please share the function that you use that the trigger is linked to?
dailyblog-demo.vercel.app/blog/1053fbb2-0018-4dd0-8f60-8282d7f9c402
You can check this and scroll to trigger function example. You can update this base on your application.
Good! One question: how do you pass the user_id to the function?
you can call auth.uid() This function will return the id of the user making the request.
@@DailyWebCoding thanks!
@@DailyWebCoding new.id is not correct?
can you share the function code?
I had the same problem... Did you raised a ticket for this?
No I haven't yet
github.com/supabase/supabase/blob/master/studio/lib/constants/schemas.ts#L5 after digging to the code. They excluded it when create a trigger
Thanks :) @@DailyWebCoding
@@DailyWebCoding can i see inside your function ? im getting error
i get permission denied when inserting row to the users table. To which role should i give the permission?
Make sure ur trigger function security is set to security definer.
@@DailyWebCoding thnx , it solved my problem. But isnt this a potential security issue? The function will be executed with the privileges of the user who created the function, rather than the user who calls the function. This means that the function may have elevated privileges, potentially bypassing some security restrictions.
@@patronovski I don't think it is a security issue. This is like a system function that will be trigger base on events and also this function can't be call beside the trigger event.
@@DailyWebCoding thats true, thanks again!
you showed me the light, auto-like and auto-subscribe
Keep getting this error: Error: AuthException(message: Database error saving new user, statusCode: 500)
Doesn't even create the auth user with this trigger on there, any ideas?
UPDATE: My other reply just now doesn't work, here is the working one:
create function public.create_user()
returns trigger
language plpgsql
security definer set search_path = public
as $$
begin
insert into public.users (user_id, email, phone)
values (new.id, new.email, new.phone);
return new;
end;
$$;
create trigger on_auth_user_created
after insert on auth.users
for each row execute procedure public.create_user();
at 3:40 you seemed to paste the same code and then it worked, do you have any idea why it worked the second time around?
Not really sure. maybe it is a bug
Weird. Thanks for the response@@DailyWebCoding
hmm i cant even create the function
Failed to create function: failed to create pg.functions: syntax error at end of input
create trigger "trigger_name"
after insert on "table_name" for each row
execute procedure trigger_function();
try using this 'procedure' instead of 'function'
I am stuck here too. He never shows the function definition, which I think we need?
@@rajikkali2381 try to write what I wrote above in SQL editor it should work fine
can u give me trigger plzzzzzzzzzzzzzz
It is in the description xD
@@DailyWebCoding the function code is never shown and is NOT in the description. For SQL noobs like myself, this makes your video useless.
@@rajikkali2381 it is useful for someone who know how to create a function
Thank you so much!