linkCredentials method

Future<User> linkCredentials(
  1. Credentials credentials

Links this User with a new User identity represented by the given credentials.

Linking a user with more credentials, mean the user can login either of these credentials. It also makes it possible to "upgrade" an anonymous user by linking it with e.g. Email/Password credentials. Note: It is not possible to link two existing users of MongoDB Atlas. The provided credentials must not have been used by another user.

The following snippet shows how to associate an email and password with an anonymous user allowing them to login on a different device.

 final app = App(configuration);
 final user = await app.logIn(Credentials.anonymous());

 // This step is only needed for email password auth - a password record must exist before you can link a user to it.
 final authProvider = EmailPasswordAuthProvider(app);
 await authProvider.registerUser("username", "password");

 await user.linkCredentials(Credentials.emailPassword("username", "password"));


Future<User> linkCredentials(Credentials credentials) async {
  final userHandle = await handle.linkCredentials(app.handle, credentials.handle);
  return UserInternal.create(userHandle, app);