Firebase Auth using phone number returns an internal error

Viewed 15852

I set up my app to be able to send Apple Notifications using firebase and I verified that it works using the console. Now I want to do phone authentication which is built on top of APN.

So I wrote this:

PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { verificationID, error in
  if error != nil {
    print("Verification code not sent \(error!)")
  } else {
    print ("Successful.")
  }

And I get:

Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={NSUnderlyingError=0x170046db0 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey={
    code = 500;
    message = "<null>";
}}}, error_name=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information.}

Any idea? Should I file a bug against firebase?

I am using iOS SDK 4.0.0 (latest zip I could find.)

UPDATE:

I disabled method swizzling by adding FirebaseAppDelegateProxyEnabled to info.plist and set it to NO

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    // Pass device token to auth.
    Auth.auth().setAPNSToken(deviceToken, type: .prod)
}
5 Answers

Well, in my case I have sending wrong self.verificationID to FIRAuthCredential. If you are having this error, then please print your verificationID and check, is that the same one you are sending to FIRAuthCredential.

Here is my code in objC :

[[FIRPhoneAuthProvider provider] verifyPhoneNumber:self.phoneNumberTextField.text
                                            UIDelegate:nil
                                            completion:^(NSString * _Nullable verificationID, NSError * _Nullable error) {
                                                if (error) {
                                                    NSLog(@"error %@", error.localizedDescription);
                                                    return;
                                                }
                                                NSLog(@"verificationID %@", verificationID);
                                                self.verificationID = [NSString stringWithFormat:@"%@", verificationID];

//                                                NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
//                                                [defaults setObject:verificationID forKey:@"authVerificationID"];
//                                                NSString *verificationID = [defaults stringForKey:@"authVerificationID"];

                                                // Sign in using the verificationID and the code sent to the user
                                                // ...
                                            }];

I accidentally send wrong verificationID here :

self.verificationID = [NSString stringWithFormat:@"verificationID",];

Right one is this :

self.verificationID = [NSString stringWithFormat:@"%@", verificationID];

And then I send it to FIRAuthCredential like this :

FIRAuthCredential *credential = [[FIRPhoneAuthProvider provider]
                                     credentialWithVerificationID:self.verificationID
                                     verificationCode:self.pinCodeTextField.text];

    [[FIRAuth auth] signInWithCredential:credential
                              completion:^(FIRUser *user, NSError *error) {
                                  if (error) {
                                      NSLog(@"error %@", error);
                                      return;
                                  }
                                  NSLog(@"Success");
                                  // User successfully signed in. Get user data from the FIRUser object
                                  // ...
                              }];

Which return success successfully. Hope it will help to others.

i am solve it easy make type .sandbox

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
    // Pass device token to auth.
    let firebaseAuth = Auth.auth()
    //At development time we use .sandbox
    firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.sandbox)
}

and remove this line from code

Auth.auth().settings.isAppVerificationDisabledForTesting = TRUE
Related