S
Supabase3mo ago
eric44

Changing email

I am using magic links and google auth for login. I plan on having a settings page where poeple can change their account. I see that once you have an email you can sign in and regardless which method its the same account. Can someone be allowed to change emails though? magic link seems doable but what would happen to the google account attached?
10 Replies
silentworks
silentworks3mo ago
Yes this can be done. The Google account would still be attached to the same user as the identity would be saved to this account already. If this is not the desired outcome you can use the unlinkIdentity to remove the Google account from this user. https://supabase.com/docs/reference/javascript/auth-unlinkidentity
JavaScript: Unlink an identity from a user | Supabase Docs
Supabase API reference for JavaScript: Unlink an identity from a user
eric44
eric44OP3mo ago
hmmm i have a google provider. if i want to change it i cvant until i have another provider so i can disconnect this one . but i dont see that email is considered a rpovider. so i cant seem to add email how do i add a email as a provider manually? i tried updating user with email i tried link identitiy but email is not a valid provider :/
silentworks
silentworks3mo ago
What do you mean by provider? Once you sign in with Google, you just updateUser and pass the new email. That’s all it is.
eric44
eric44OP3mo ago
i currenlty have google provider. now i wanrt to add my email as one of the providers. it will be klisted in the column providers. const { error } = await supabase.auth.updateUser({ email: newEmail, }); this doesnt work
silentworks
silentworks3mo ago
This works. It's what I'm doing in my code that I tested. If you have email confirmation on, you will get an email sent to the new email address and the existing one from the Google provider. Once you confirm those emails via a link sent to you, it will update to the new email in the database.
eric44
eric44OP3mo ago
it seems to be working now. for a little while it was sending a email with numbers for confirming. but i use magic links and dont require a number o anything like that i see. i think i figured out the issue. if im already signed up with that email via google provider, i can no longer add the same email as a magic link?
silentworks
silentworks3mo ago
I don’t think you would need to add it as a provider as you should still be able to sign in with magic link of the email is the same.
eric44
eric44OP3mo ago
well i switched on mnamually link identities so poeple could technically change their google identity and or email
silentworks
silentworks3mo ago
I don't understand what you mean by this? an email isn't linked, it is updated using the updateUser method. Only OAuth providers uses the linkIdentity method.
eric44
eric44OP3mo ago
i gave users the option to use google or magic link. if they decide they want to change their email i didnt want the magic link and the google auth to be connected. maybe they want to sign in via google on one email address or maybe they have a magic link with a different address so i set the manual identities

Did you find this page helpful?