Docs Menu

Link User Identities - Flutter SDK

On this page

  • Example

Atlas App Services provides multiple authentication providers to log users into your app. Each provider creates a unique user identity. App Services lets you merge multiple credentials into one user identity.

You can link identities by passing the Credentials that you want to link to User.linkCredentials().

User linkedCredentialUser =
await user.linkCredentials(additionalCredentials);

Consider an application that offers anonymous login. This allows users to explore the app without registering. If users like the application, they create permanent accounts. They sign up with SSO or email/password authentication. By default, this creates a new User object. The app must link the new identity with the original User.

We must first register the new email/password user before linking.

// on app start without registration
User anonymousUser = await app.logIn(Credentials.anonymous());
// ... user interacts with app
//... user decides to sign up for app with email/password auth
EmailPasswordAuthProvider authProvider = EmailPasswordAuthProvider(app);
await authProvider.registerUser(USERNAME, PASSWORD);
// link email/password credentials to anonymous user's credentials
User linkedCredentialUser = await anonymousUser
.linkCredentials(Credentials.emailPassword(USERNAME, PASSWORD));
←  Work with Multiple Users - Flutter SDKCustom User Data - Flutter SDK →

On this page

Give Feedback
© 2022 MongoDB, Inc.

About

  • Careers
  • Investor Relations
  • Legal Notices
  • Privacy Notices
  • Security Information
  • Trust Center
© 2022 MongoDB, Inc.