I've started to setup Firebase Phone authentication in Flutter based on the official documentation. Unfortunately, no matter how I try, I get a FirebaseAuthException in the verificationFailed callback of the verifyPhoneNumber method with these values:
code: "invalid-app-credential"
credential: null
email: null
message: "Token mismatch"
phoneNumber: null
plugin: "firebase_auth"
stackTrace: null
tenantId: null
I've created a simple repository to reproduce the issue: https://github.com/peternagy1332/basic_phone_auth
flutterfire configure to add the app to an existing Firebase project and create the IOS application there.[email protected] and [email protected]Push notification and Background modes capability with Background fetch and Remote notifications options.REVERSED_CLIENT_ID from GoogleService-Info.plist as an URL Scheme.Apple Push Notifications service (APNs) service and uploaded it as an APNs Authentication Key to Firebase.The setup section of the official documentation points me to this documentation. This indicates that additional modifications in the Swift code might be needed, but it's really unclear. I'm a Flutter developer and not a native IOS developer, I don't think I actually need to do all that.
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure()
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
let firebaseAuth = Auth.auth()
firebaseAuth.setAPNSToken(deviceToken, type: AuthAPNSTokenType.unknown)
}

In a Flutter application I was facing firebase_auth/invalid-app-credential: Invalid token error. The game changer for me was adding the APNs auth key to Firebase. In order to do that:
1 - Go to the Apple Developer website and create an Apple Push Notifications service (APNs) key. Then download it.
2 - In the Firebase > Project Settings > Cloud Messaging > Apple app configuration upload the APNs key.
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