Navigation

Link User Identities

MongoDB 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.

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: Realm.User, email: string, password: string) {
const emailPasswordUserCredentials = Realm.Credentials.emailPassword(
email,
password
);
await user.linkCredentials(emailPasswordUserCredentials);
}
Give Feedback