This is my code:
import FirebaseAuth class AuthPhoneNum { static func getPhoneNum(phoneNumber: String) { PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber) { (verificationID, error) in if let error = error { print(error) return } UserDefaults.standard.set(verificationID, forKey: "authVerificationID") } } static func verify(verificationCode: String?) { guard let verificationID = UserDefaults.standard.string(forKey: "authVerificationID") else { return } if verificationCode != nil { let credential = PhoneAuthProvider.provider().credential( withVerificationID: verificationID, verificationCode: verificationCode!) Auth.auth().signIn(with: credential) { (user, error) in if let error = error { print(error) return } } } else { print("No verification code") } } }
This is what the console prints out:
Error Domain=FIRAuthErrorDomain Code=17048 "Invalid token." UserInfo={NSLocalizedDescription=Invalid token., error_name=INVALID_APP_CREDENTIAL}
What am I doing wrong? Thanks
In the Firebase console, open the Authentication section. In the Sign in method tab, enable the Phone provider if you haven't already. Open the Phone numbers for testing accordion menu. Provide the phone number you want to test, for example: +1 650-555-3434.
When a user or device successfully signs in, Firebase creates a corresponding ID token that uniquely identifies them and grants them access to several resources, such as Firebase Realtime Database and Cloud Storage. You can re-use that ID token to identify the user or device on your custom backend server.
I was also experiencing this problem. Checked the following:
aps-environment
valueauth.setAPNStoken
(.unknown
for auto detect)Nothing helped until in Firebase app settings I uploaded the APNS authentication key (p8) instead of certificates - I used those certificates before for push notifications only and everything was working fine but for phone number notifications something went wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With