How can I check if a user exists before creating an Account using OAuth?
When a user clicks sign in with google on my app's login screen it creates an account for them and signs them up, even if the user didn't exist before. I want to check if the user exists and if they don't I don't want to sign them up. I just don't know how to check if an OAuth user exists.
Any help would be appreciated
14 Replies
If I where doing it, I would look at this hook and check if the user email exists.
I've not tried it so you would need to experiment. Also how are you creating the users if you don't want to create them with the OAuth? Things could be more complicated if you have to deal with other signup methods. https://supabase.com/docs/guides/auth/auth-hooks/before-user-created-hook?queryGroups=language&language=http
I've not tried it so you would need to experiment. Also how are you creating the users if you don't want to create them with the OAuth? Things could be more complicated if you have to deal with other signup methods. https://supabase.com/docs/guides/auth/auth-hooks/before-user-created-hook?queryGroups=language&language=http
Well I just don't want them to create an oAuth account on the login page they, if they have a Google account, then they should be able to use that to log in, but if they don't, it should redirect them to the signup page
I just really want to be able to check if the user exists before they try and sign in with Google or Apple.
And thank you for the response. I will look at the hook
Why is it that you want to check if they have an account before oauth? Provided a user account maps to the same email (which is the only way to tell duplicates) then is it an issue if they use multiple methods to sign up

Here is an example i have of a user that has multiple providers i.e they sign up with google and github using the same email mapping
Well they're in the login page so I want to make sure that they have an account, if not they should go to the sign in page
Also so I can set up their profile
If they're a new user
Otherwise just sign them in (if they have an account)
from the perspective of oauth it doesnt distinguish between sign up and login i think
i am using
for login and register
It might be better to have a profile table, where you create a profile when a new user is added to auth and have a field
profile_complete
as a boolean that will prompt the user for profile setupOh yeah that might be a better alternative
Yeah it doesn't
But also then users are just able to sign up through the log in page, which might be a bit confusing
maybe, but it should be fine i think. As a user i probably know whether or not i have an account with a company and even if i didn't i want an account at the time i press "log in"
some places might avoid using "log in" and "register" and instead use "continue with ..." as the prompt
if that helps
So is there no way to just check if the oAuth account exists, before signing in?
i can't find anything related to that functionality
There is no built in way. With OAuth you don't know the email until the process has started on Supabase's side so you can't do it in your client.
I'll add my opinion here, from an end user perspective : it pisses me off when on a login page I cannot create an account by using Login With Google and when it explicitly asks to go signup page
Joining advices above : allow OAuth account creation on both pages and then adapt the flow about the page to show weither or not they have finished their profile setup
Got it, thank you so much for your input