Link User Identities
Overview
Realm provides multiple ways for users to log into your application. Because each method of authentication corresponds to a unique user identity, Realm lets you merge multiple identities belonging to a single user into one user identity.
Example
Consider an application that enables users to authenticate via anonymous authentication. When that user decides to create a full account with an SSO provider or email/password authentication, you need some way of persisting the user's original anonymous identity with their new permanent identity.
You can link identities using the linkCredentials()
method
of the User
object of a logged-in User.
async function linkAccounts(user, email, password) { const emailPasswordUserCredentials = Realm.Credentials.emailPassword( email, password ); await user.linkCredentials(emailPasswordUserCredentials); return user; }