Navigation

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

let client = app.usernamePasswordProviderClient()
client.registerEmail(username, password: password, completion: { (error) in
  // Handle errors...
  // Registering just registers. You can now log in.
}
RLMApp *app = [RLMApp appWithId:@"myappid"];

RLMUsernamePasswordProviderClient *client = [app usernamePasswordProviderClient];
[client registerEmail:@"someone@example.com" password:password completion:^(NSError *error) {
    // If no error, user registered
}];

Confirm a New User’s Email Address

let client = app.usernamePasswordProviderClient()

// Token and tokenId are query parameters in the confirmation
// link sent in the confirmation email.
confirm.confirmUser(token: token, tokenId: token, completion: { (error) in
    // Handle errors...
    // User email address confirmed.
}
// Token and tokenId are query parameters in the confirmation
// link sent in the confirmation email.
[client confirmUser:token tokenId:tokenId completion:^(NSError *error) {
   // If no error, user confirmed
}];

Reset a User’s Password

// Send the reset password email
client.sendResetPasswordEmail(email, completion: {(error) in
    // If no error, email sent
})

// Later...

let newPassword = "mynewpassword12345"
// Token and tokenId are query parameters in the reset password
// link sent in the reset password email.
client.resetPassword(to: newPassword, token: token, tokenId: tokenId, completion: {(error) in
    // If no error, password was reset
})
// Send the reset password email
NSString *email = @"someone@example.com";
[client sendResetPasswordEmail:email completion:^(NSError *error) {
   // If no error, email sent
}];

NSString *newPassword = @"mynewpassword12345";
// Token and tokenId are query parameters in the reset password
// link sent in the reset password email.
[client resetPasswordTo:newPassword token:token tokenId:tokenId completion:^(NSError *error) {
   // If no error, password was reset
}];