https://supabase.com/ logo
when I try to sign in via magic link I get the err...
# help
h
when I try to sign in via magic link I get the error
Copy code
duplicate key value violates unique constraint "users_pkey"
n
Hello @hanako! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
g
Do you have a trigger function on auth.users to add to another table?
h
but no differnce 😦
g
but no difference?
h
I still get the same error
Copy code
duplicate key value violates unique constraint "users_pkey"
g
I glanced at the first post there and that also triggers on update which won't work with just an insert to your public table. SignUp will insert to the auth.users table then when magic link is confirmed update it. That function triggers on both and tries to insert again and can't. The function is not good.
Or at least calling it with an update trigger is not good.
h
What I want to accomplish is : I have created user, post etc in prisma schema. when I login through magic link let's say, it shows up in authentication>users but not in table>editor>all tables>users. I want supabase-auth users to show up in prisma users
g
That is fine, you just can't call that function on an update. Just insert. Otherwise you need more logic.
h
this was marked as answer so I just pasted it and ran in sql editor
g
The marked answer looks better. It does only an insert trigger. The first post does both.
h
so which one? 😅
I tried this one
g
Is your trigger just insert like shown in your last picture, or does it include update also?
h
I just copy pasted this code into the editor
I'm new to supabase and postgresql so I need to learn more to write on my own
g
You have a table called users in public?
h
yes
here's the schema just in case
g
The error is saying you are trying to insert the same ID twice which is illegal for a primary key (hence my concern about update, but you show only an insert trigger, which is good). You also have the table declared public.users in the function, so it should not get confused with auth.users.
h
🥲
g
In your model you also have email as unique. Is it possible you are reusing the email for different tries and the old user still exists in your public.users table?
h
I am reusing for trying but it doesn't exist in public.users table. that and all prisma defined tables are empty as I haven't set up anything yet. tho when it worked two days ago the user would show up in auth.users
not in both (as I need)
g
If you go to the dashboard/database/triggers you can remove the trigger. (You will have to rerun the last part of the sql again later to redo it). If you remove the trigger see if you can signIn a user.
h
its the second one right?
.
also, is first one needed?
I might've pasted another one
g
Could be your problem if they both trigger
h
ok im deleting 2nd
oO it works now
I mean the login thing
thank you very much
wow it also shows up in public.users table
one small thing though
in public.users table, when I sign up it creates the user and with the same id (which is great) but doesn't show the email
I'm guessing thats a problem on my part. I declared schema in a wrong way or something? could you suggest a fix?
g
For what you started this with, the fix is to only have one trigger on auth.users calling the function.
Sorry, that was weird just your last line was showing when I looked on my iPad... Let me glance at the function.
h
yea I had tried adding triggers in editor but didn't delete them
any idea about this?
g
Can you show me your current trigger
h
oh I dont have any I think
g
So you got rid of the trigger than called your signup_copy..... function and it appears you have another function handle_new_user_public that probably does no insert email.
You had two functions and two triggers....
h
oh so should I remove the
on_auth_user_created
trigger and add the one I deleted earlier?
g
YES
I did not realize you also had two functions...
h
this one is default? I think. I didn't add it
g
There is no default.
Maybe some starter template you used or something.
If you go look at the handle_new_user function in database/functions you will probably see that it only inserts new.id and not email. You should be able to delete that function and just use your sign_up_copy_to_users function.
h
cool
will try
g
If you have further issues, start a new thread, I'm gone for a bit and you are not likely to get views in this one after this many posts. Good Luck.
h
it works now. the user shows up in both auth and public and also shows email!
thank you very much. appreciate your help
n
Thread was archived by @hanako. Anyone can send a message to unarchive it.