Hi ! I’m having trouble understanding when to use the linkCredentials method.
I am using both the Email/Password and the Google authentication methods provided by the Realm API. Since the Google sign in/log in uses the same .logIn()
method to both create a new user and log in an existing user, a problem arises in the following case: if my user already has signed up using Email/Password and he/she later tries to log in with Google (by mistake, let’s say), Realm doesn’t detect that the email is already used and it creates a new account.
The obvious solution to my problem would be to use the linkCredentials
method but when am I supposed to use it? In the scenario I described, when my user tries to log in with Google, I only get access to the user
object inside the .then()
part of the .logIn()
promise, and at this point a duplicate user has already been created - this post indicates that it is impossible to link two existing users linkCredentials with an existing Google user
I created a function which combined with a webhook allows me to check whether the email is already used, but - same issue - I don’t see where I could add this check in the Google auth flow as the .then()
part of the logIn()
method is called when the user selects the account in the list of Google accounts, leaving me no moment when I do know the email address of the Google account in order to check if it is already used before the duplicate user is added.
This is really problematic and I would appreciate any hints/ideas on the topic.
Many thanks,
Benjamin