0

I'm starting to use Realm.js as the database for my android apps but I have a problem understanding why if I log with invalid credentials it doesn't give me an error but instead it creates a new user.

I'd like to avoid this from happening and give the user an error? Am I supposed to check manually if the user exists before calling the login function (before doing it after will always return true)?

try {
      // Reset any previous errors that might have happened
      this.setState({ error: undefined });
      // Attempt to authenticate towards the server
      const credentials = Realm.Sync.Credentials.usernamePassword(nickname, '123'); // 123 password is hard coded,this is only for testing
      const user = await Realm.Sync.User.login(SERVER_URL, credentials);

      // Hide the modal
      this.setState({ isModalVisible: false });
      this.onAuthenticated(user);
} catch (error) {
      this.setState({ isModalVisible: true, error });
}
DxW
  • 1,414
  • 3
  • 11
  • 23

1 Answers1

0

Just add false at this line, the user is not created on login, but on credentials building.

  const credentials = Realm.Sync.Credentials.usernamePassword(nickname, '123', false); // 123 password is hard coded,this is only for testing
DxW
  • 1,414
  • 3
  • 11
  • 23