Linking same user with different authentication providers

Use Case
Suppose, user Scott has logged in with an email/password on the first day. After few days, he logs in with another provider say, Google Authentication Provider with the same email (as the earlier one).

Problem
MongoDB Realm creates two different users: provider type Username/Password, local-userpass and the other with Google, OAuth-2-google. How do I link these two identities with the original user when the user logs in with the second provider?

I’m not sure which SDK you’re using, but I believe you’ll find what you’re looking for under the SDK -> Advanced Guides -> Link User Identities page. For example, the Android SDK has a linkCredentials() method for the User object: https://docs.mongodb.com/realm/sdk/android/advanced-guides/link-user-identities/

Does this help?

Thanks for your reply. I am using realm-web SDK. Please elaborate the flow that I need follow.

Please note, while 2nd time user is signing in with Google authentication provider, at the client side, I am not aware of the fact that whether the user is a returning user and has already signed up with email password or not.

Great point. I saw from your documentation feedback that you found the Web SDK documentation for linking user identities and it didn’t have this info for you. I don’t have a good suggestion for handling this, but I’ll check with my team and see what we recommend. I’ll make sure to let you know what I find out, and we’ll make a ticket to update the documentation. Thanks for filing the feedback - that’s really helpful!

1 Like

Thanks for your reply. I will be waiting for the solution.

I checked with my team, and it looks like there isn’t a recommendation for how to solve this if you don’t know that the user will want to link user identities from the beginning. Once the user has authorized via Google or Facebook and we notice that the emails match, it’s too late to address this.

Sorry I don’t have a more helpful answer for you. I’ve made a note that this is problematic, and will be sure to update the docs in the future if we make enhancements to Realm user management that might improve this.

1 Like