realm / realm-object-server

Tracking of issues related to the Realm Object Server and other general issues not related to the specific SDK's
https://realm.io
293 stars 42 forks source link

"Invalid credential" error returned instead of "user already exists" #427

Open cbush opened 5 years ago

cbush commented 5 years ago

Using username/password authentication to log in as an existing user with register == true, I get the "invalid credential" error code, not the "user already exists" error. Likewise, if I log in as a non-existent user with register == false, I get "invalid credential" instead of "user does not exist". Is this a bug?

I have checked that username/authentication is enabled on my instance and email validation is disabled. I can see that the users are being created the first time.

Goals

I would like to have special code to handle the case where the user already exists, but with the same error returned I can't distinguish this error from any other auth error.

Expected Results

userAlreadyExists error code (613)

Actual Results

invalidCredential error code (611)

Steps to Reproduce

  1. Log in (registering a new user)
  2. Log out
  3. Log in again as the same user (register still set to true)
  4. Handle error and check the code

Code Sample

let creds = SyncCredentials.usernamePassword(username: name, password: "password", register: true);

SyncUser.logIn(with: creds, server: Constants.AUTH_URL, onCompletion: { [weak self](user, err) in
    if let _ = user {
        // login successful
    } else if let error = err as? SyncAuthError {
        switch error.code {
            case .userDoesNotExist: // never hit!
                fatalError(error.localizedDescription);
            case .userAlreadyExists: // never hit!
                fatalError(error.localizedDescription);
            case .invalidCredential: // this is always the case
                fatalError(error.localizedDescription);
            default:
                break;
        }

    }
})

Version of Realm and Tooling