Hey guys, have ran into a small issue recently regarding auth. I have an app where a user can log in with google, log in with github, etc.
So, if a user with [email protected] makes a google account that creates user_id 1234
and then that user tries to log in with github that is also tied to [email protected], how would the best way to handle this be?
I assume making a new account for the user is bad, but also checking by email is bad (what if the one using github [email protected] is malicious/someone else).
I am thinking to have it so there is an external_account table which holds the provider (e.g. GOOGLE, GITHUB), and then user_id that points to user:
So like
user = {
id: 1234,
email: "[email protected]"
}
external_account_1 = {
id: "some-google-id",
user_id: 1234,
provider: GOOGLE,
provider_user_id: "users-google-id-thing"
}
external_account_2 = {
id: "some-github-id",
user_id: 1234,
provider: GITHUB,
provider_user_id: "users-github-id-thing"
}
But i genuinely don't know how the flow would look. From a UX perspective, i've never had to myself do a "first login with your existing google account then login with github to link it" so i don't think this is the best way.
Should i just not allow them to make a github account if they already made a google account with the same email? And just say "user already exists with this email, please log in with google instead".
Should i let them after auth with google go to a page where they can also "link github"? But not during login just after they login with google they can themselves go to the link accounts page?