dijonmusters / build-a-twitter-clone-with-the-next.js-app-router-and-supabase

This repo accompanies a free egghead course where we build a Twitter clone with the Next.js App Router and Supabase 🚀
https://egghead.io/courses/build-a-twitter-clone-with-the-next-js-app-router-and-supabase-19bebadb?af=9qsk0a
93 stars 9 forks source link

Cannot create Triggers for auth schema - Missing "users" table from table dropdown #11

Open kmiguel10 opened 1 year ago

kmiguel10 commented 1 year ago

I am stuck in chapter 12 because when creating a trigger to watch for a changes in the users table in auth schema , the dropdown for the Table (to watch for) options only shows my 2 public tables which are profiles and tweets but it should show the users table.

From tutorial:

Screenshot 2023-10-03 at 11 29 41 AM

Issue: Screenshot 2023-10-03 at 11 30 33 AM

Thanks!

jundran commented 1 year ago

I had the same problem using the GUI but I was using the code snippets to create the function and the trigger. These seemed to work but then when I would log in on the app, I would get back a session but supabase would fail to save the user to the auth table. If I deleted the trigger using the query drop trigger <TRIGGER NAME> on auth.users; then supabase would save the user to auth.users but, of course, nothing would be in the profiles table.

I ended up deleting the profiles table, function, trigger and the modifying the User Management Starter template to work with this tutorial. You can see the templates in the SQL editor. Basically, just modify the values to match the values we want in the profiles table. Edit the values in the part for creating the profiles table and the arguments for the public.handle_new_user function. Run it then don't forget to re add the foreign key relation between the tweets table user_id and the profiles table with cascade on delete.

britotiagos commented 11 months ago

@kmiguel10 you can find the solution for that in this video.

Basically, all you have to do is run this in the SQL editor, changing it to your own information.

kevinhellos commented 5 months ago

This is the command that I used, it works for me as of June 5 2024.

CREATE TRIGGER users_insert_trigger
AFTER INSERT ON auth.users
FOR EACH ROW
EXECUTE FUNCTION insert_profile_for_new_user();