Manage Email/Password Users¶
Overview¶
When you have enabled the email/password provider in your Realm app, you can register a new account, confirm an email address, and reset a user's password from client code.
Register a New User Account¶
To register a new user, pass a user-provided email and password to the
registerUser()
or registerUserAsync()
methods of your Realm App
's EmailPasswordAuth
instance:
app.emailPassword.registerUserAsync(email, password) { if (it.isSuccess) { Log.i("EXAMPLE","Successfully registered user.") } else { Log.e("EXAMPLE","Failed to register user: ${it.error}") } }
Confirm a New User's Email Address¶
To confirm a newly-created user, pass a confirmation token
and
tokenId
to the confirmUser()
or confirmUserAsync()
methods of your Realm App
's EmailPasswordAuth
instance:
// token and tokenId are query parameters in the confirmation // link sent in the confirmation email. app.emailPassword.confirmUserAsync(token, tokenId) { if (it.isSuccess) { Log.i("EXAMPLE", "Successfully confirmed new user.") } else { Log.e("EXAMPLE", "Failed to register user: ${it.error}") } }
To access the token
and tokenId
values sent in the user
confirmation email, you can use a custom confirmation email subject containing a deep link.
Reset a User's Password¶
To reset a user's password, first send the user a password reset email with sendResetPasswordEmail() or sendResetPasswordEmailAsync():
app.emailPassword.sendResetPasswordEmailAsync(email) { if (it.isSuccess) { Log.i("EXAMPLE", "Successfully sent the user a reset password link to $email") } else { Log.e("EXAMPLE", "Failed to send the user a reset password link to $email: $it.error") } }
Password reset emails contain two values, token
and tokenId
.
To complete the password reset flow, prompt the user to enter a new
password and pass the token
and tokenId
values along with the
new password value to your Realm App
's
EmailPasswordAuth
instance's resetPassword()
or resetPasswordAsync()
methods:
// token and tokenId are query parameters in the confirmation // link sent in the password reset email. app.emailPassword.resetPasswordAsync(token, tokenId, newPassword) { if (it.isSuccess) { Log.i("EXAMPLE", "Successfully updated password for user.") } else { Log.e("EXAMPLE", "Failed to reset user's password: $it.error") } }
To access the token
and tokenId
values sent in the password
reset email, you can use a custom password reset email subject containing a deep link.