Using the nextjs-subscription-auth example, I noti...
# help
s
Using the nextjs-subscription-auth example, I noticed there was a users table in the db when using that template, and I went through the code, but I was curious at what point is the users table created/queried upon to create that user entry? the columns for the user schema have some info for other table relations, but I wanted to ensure that the user email was inside that table as well, and by default it is not. is this not something that supabase auth handles automatically? I know that the email can be read from the supabase.auth itself in the session, etc, I just wanted to get a better idea the actual flow of it i guess.
j
The users are inserted in to the public.users table with the help of a trigger and a function after they've signed in for the first time. You can find this in the schema.sql file. I'll post a picture as well. If I understand you correctly you would also like to have the users email in the public.users table as well? In that case you must add that column to the public.users table and change the function a bit:
Copy code
create function public.handle_new_user() 
returns trigger as $$
begin
  insert into public.users (id, email, full_name, avatar_url)
  values (new.id, new.email, new.raw_user_meta_data->>'full_name', new.raw_user_meta_data->>'avatar_url');
  return new;
end;
Hope that helps!
s
thank you, now if i did't actually start with the supabase template, but want to use the code to implement auth/subscriptions into an existing project, how exactly is the schema.sql file loaded? I just noticed this file's existence tbh. But thank you for pointing this out. I guess my question is how and when does your supabase client recognize and use this file, and if i already have the tables in the db should I just start a new Supabase project and wait to execute that schema.sql file at that point?
@User here is what I mean
I am not actually using this template in my project, rather implementing the auth and subscription functionality myself based on the code in the repo
s
@User its hard to keep track of what you are asking because you wrote in #843999948717555735 and then pinged me in here
no sql file are run automatically, you have to manually execute them
So copy the content from schema.sql and paste in the sql editor inside the UI
s
sorry, was just referencing what I meant in main #843999948717555735
ahh so this would me something I manually do when I start the project in supabase, and the project deploy automatically does this?
s
No it doesn't do this if its deployed via the vercel button
You still have to run that part manually
s
If that is the case then why when I did the vercel deploy, was there already all tables made in the new DB project?