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

Комментарии • 67

  • @markbroomfield1818
    @markbroomfield1818 10 месяцев назад +2

    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

  • @user-mu8xm5hf8h
    @user-mu8xm5hf8h 7 месяцев назад +3

    Thank you so much! I was stuck at making trigger on auth table. Your video helps me a lot!

  • @edensaltzman1146
    @edensaltzman1146 7 месяцев назад +2

    Thanks for the workaround! Worked like a charm.

  • @PiyushRaj-ij3dx
    @PiyushRaj-ij3dx 7 месяцев назад +1

    Exactly what I needed! Thank you so much!

  • @osmanakar2507
    @osmanakar2507 10 месяцев назад +1

    thank you for the workaround 🙌 keep going with great the Supabase contents.

  • @julienheng3880
    @julienheng3880 6 месяцев назад +1

    Thank you so much for your tutorial! it is really helpful!

  • @mateussoares7599
    @mateussoares7599 8 месяцев назад +1

    thanks man this helped me, straight to the point

  • @therhythmatic
    @therhythmatic 8 месяцев назад +1

    This was clutch, thank you!

  • @olekzaytsev3582
    @olekzaytsev3582 3 месяца назад

    Thanks mate! Very nice video, appreciate it.

  • @tokenizatumarca
    @tokenizatumarca 4 месяца назад +1

    Great content man! Super useful 🙏

  • @iamchu
    @iamchu 9 месяцев назад +1

    Thanks for this!

  • @HenriqueAntonioBarbosa
    @HenriqueAntonioBarbosa 2 месяца назад

    Thank you so much!

  • @valentinlorentejimenez2918
    @valentinlorentejimenez2918 4 месяца назад +1

    Really appreciated!

  • @chas.porter
    @chas.porter 5 месяцев назад +1

    That solved it! Thank you!

  • @vommir.
    @vommir. 3 месяца назад

    Really nice, thank you.

  • @filip_wojda
    @filip_wojda 4 месяца назад +1

    thank you for this

  • @sujitragav3962
    @sujitragav3962 3 месяца назад

    Thanks it really helped

  • @surething3103
    @surething3103 9 месяцев назад +1

    Thanks a lot

  • @makkhawanvoraboot1946
    @makkhawanvoraboot1946 5 месяцев назад +1

    thanks you alot broo

  • @CC-xv7hf
    @CC-xv7hf 2 месяца назад +1

    ty 💋

  • @rajikkali2381
    @rajikkali2381 8 месяцев назад +6

    Where is the create_user_on_signup function definition code??

    • @abdulsamadayoade9439
      @abdulsamadayoade9439 3 месяца назад +3

      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;

  • @lukem829
    @lukem829 3 месяца назад +1

    thanks a lot!

  • @reikoleci4689
    @reikoleci4689 День назад

    you the best

  • @NagatoKamiPain
    @NagatoKamiPain 6 месяцев назад +5

    where can I find function that you used?

    • @keemkorn
      @keemkorn 4 месяца назад

      bro, just make it??

  • @curious_cat505
    @curious_cat505 25 дней назад +1

    Great, but you only needed 2 minutes

  • @ambicasupraja9651
    @ambicasupraja9651 7 месяцев назад

    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

  • @tarunfreestone6024
    @tarunfreestone6024 2 месяца назад

    I am stuck, supabase is not recognising the function i have created, is it security definer or invoker in advanced settings.

  • @Raisingyourbloodpressure
    @Raisingyourbloodpressure 4 месяца назад

    Why did they take it out in the first place? Does anyone know?

  • @c0dingwithchris
    @c0dingwithchris 5 месяцев назад +1

    Could you please share the function that you use that the trigger is linked to?

    • @DailyWebCoding
      @DailyWebCoding  5 месяцев назад

      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.

  •  5 месяцев назад

    Good! One question: how do you pass the user_id to the function?

    • @DailyWebCoding
      @DailyWebCoding  5 месяцев назад +1

      you can call auth.uid() This function will return the id of the user making the request.

    •  5 месяцев назад

      @@DailyWebCoding thanks!

    • @ThisIsChina-mu1ls
      @ThisIsChina-mu1ls 3 месяца назад

      @@DailyWebCoding new.id is not correct?

  • @chrstnrcg
    @chrstnrcg 2 месяца назад

    can you share the function code?

  • @kamil_supabase_enjoyer
    @kamil_supabase_enjoyer 10 месяцев назад +2

    I had the same problem... Did you raised a ticket for this?

    • @DailyWebCoding
      @DailyWebCoding  9 месяцев назад +1

      No I haven't yet

    • @DailyWebCoding
      @DailyWebCoding  9 месяцев назад +1

      github.com/supabase/supabase/blob/master/studio/lib/constants/schemas.ts#L5 after digging to the code. They excluded it when create a trigger

    • @kamil_supabase_enjoyer
      @kamil_supabase_enjoyer 9 месяцев назад

      Thanks :) @@DailyWebCoding

    • @EverythingWithKotlin
      @EverythingWithKotlin 9 месяцев назад

      @@DailyWebCoding can i see inside your function ? im getting error

  • @patronovski
    @patronovski 8 месяцев назад +2

    i get permission denied when inserting row to the users table. To which role should i give the permission?

    • @DailyWebCoding
      @DailyWebCoding  8 месяцев назад +1

      Make sure ur trigger function security is set to security definer.

    • @patronovski
      @patronovski 8 месяцев назад

      @@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.

    • @DailyWebCoding
      @DailyWebCoding  8 месяцев назад +1

      @@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.

    • @patronovski
      @patronovski 8 месяцев назад

      @@DailyWebCoding thats true, thanks again!

  • @heugh_jazz
    @heugh_jazz 8 месяцев назад +1

    you showed me the light, auto-like and auto-subscribe

  • @XIIOSRS
    @XIIOSRS 3 месяца назад

    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?

    • @XIIOSRS
      @XIIOSRS 3 месяца назад

      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();

  • @anthonyngooo
    @anthonyngooo 9 месяцев назад

    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?

    • @DailyWebCoding
      @DailyWebCoding  9 месяцев назад +1

      Not really sure. maybe it is a bug

    • @anthonyngooo
      @anthonyngooo 9 месяцев назад

      Weird. Thanks for the response@@DailyWebCoding

  • @leocaesar2
    @leocaesar2 9 месяцев назад +1

    hmm i cant even create the function
    Failed to create function: failed to create pg.functions: syntax error at end of input

    • @yasminelmahdi2003
      @yasminelmahdi2003 8 месяцев назад

      create trigger "trigger_name"
      after insert on "table_name" for each row
      execute procedure trigger_function();
      try using this 'procedure' instead of 'function'

    • @rajikkali2381
      @rajikkali2381 8 месяцев назад

      I am stuck here too. He never shows the function definition, which I think we need?

    • @yasminelmahdi2003
      @yasminelmahdi2003 8 месяцев назад

      @@rajikkali2381 try to write what I wrote above in SQL editor it should work fine

  • @maybe_omuamua
    @maybe_omuamua 8 месяцев назад +1

    can u give me trigger plzzzzzzzzzzzzzz

    • @DailyWebCoding
      @DailyWebCoding  8 месяцев назад

      It is in the description xD

    • @rajikkali2381
      @rajikkali2381 8 месяцев назад +1

      ​@@DailyWebCoding the function code is never shown and is NOT in the description. For SQL noobs like myself, this makes your video useless.

    • @DailyWebCoding
      @DailyWebCoding  8 месяцев назад +2

      @@rajikkali2381 it is useful for someone who know how to create a function

  • @michaeldeveloper831
    @michaeldeveloper831 8 месяцев назад +1

    Thank you so much!