invertase / react-native-firebase

🔥 A well-tested feature-rich modular Firebase implementation for React Native. Supports both iOS & Android platforms for all Firebase services.
https://rnfirebase.io
Other
11.56k stars 2.19k forks source link

[🐛] 🔥 expo (eas) app -- error when calling `signInWithPhoneNumber` only on device -- [auth/invalid-app-credential] Invalid token #6894

Closed tycobbb closed 1 year ago

tycobbb commented 1 year ago

Issue

only on device, and currently only tested on an ios, calling auth().signInWithPhoneNumber(...) produces an [auth/invalid-app-credential] Invalid token. in the simulator, the recaptcha appears and the phone number verification flow is successful.


Project Files

i've included the relevant expo config files, and scrubbed them of most of the identifiable details. you'll have to trust that where it says bundle-id-dev that it's a real and valid bundle id that's the same in all of those places.

Javascript

Click To Expand

```js await auth().signInWithPhoneNumber(""); ``` #### `package.json`: ```json { "version": "1.0.0", "dependencies": { "@config-plugins/android-jsc-intl": "^4.0.0", "@expo/html-elements": "^0.2.2", "@react-native-async-storage/async-storage": "~1.17.3", "@react-native-firebase/app": "^16.4.6", "@react-native-firebase/auth": "^16.4.6", "@react-native-masked-view/masked-view": "0.2.8", "@react-navigation/bottom-tabs": "^6.4.0", "@react-navigation/native": "^6.0.13", "@react-navigation/native-stack": "^6.9.1", "@rneui/base": "^4.0.0-rc.6", "@rneui/themed": "^4.0.0-rc.6", "@shopify/flash-list": "1.3.1", "@types/lodash": "^4.14.188", "date-fns": "^2.29.3", "date-fns-tz": "^1.3.7", "eas-cli": "^3.5.2", "expo": "^47.0.0", "expo-build-properties": "~0.4.1", "expo-dev-client": "~2.0.1", "expo-image": "^1.0.0-alpha.5", "expo-linear-gradient": "~12.0.1", "expo-linking": "~3.3.0", "expo-location": "~15.0.1", "expo-splash-screen": "~0.17.5", "expo-status-bar": "~1.4.2", "expo-task-manager": "~11.0.1", "expo-updates": "~0.15.6", "geolib": "^3.3.3", "jest": "^26.6.3", "jest-expo": "^47.0.0", "libphonenumber-js": "^1.10.14", "lodash": "^4.17.21", "react": "18.1.0", "react-dom": "18.1.0", "react-native": "0.70.5", "react-native-safe-area-context": "4.4.1", "react-native-screens": "~3.18.0", "react-native-svg": "13.4.0", "react-native-web": "~0.18.7" }, "devDependencies": { "@babel/core": "^7.19.3", "@babel/plugin-transform-modules-commonjs": "^7.18.6", "@babel/preset-typescript": "^7.18.6", "@faker-js/faker": "^7.6.0", "@testing-library/jest-native": "^5.1.2", "@testing-library/react-native": "^11.2.0", "@types/jest": "^29.1.1", "@types/react": "~18.0.24", "@types/react-native": "~0.70.6", "babel-plugin-transform-inline-environment-variables": "^0.4.4", "husky": "^8.0.0", "jest-mock-extended": "^3.0.1", "prettier": "^2.7.1", "pretty-quick": "^3.1.3", "react-test-renderer": "18", "typescript": "^4.6.3" }, "resolutions": { "expo-modules-autolinking": "~1.0.0", "@expo/config-plugins": "^5.0.2", "@expo/prebuild-config": "^5.0.5" }, "private": true } ``` #### `firebase.json` for react-native-firebase v6: ```json # N/A ``` #### `app.config.js` (for expo) ```js import { merge, omit } from "lodash"; // -- config -- const config = () => { const env = dev; const envConfig = omit(env, "firebase"); const config = merge(shared(env), envConfig); return config; }; const shared = (env) => ({ ..., ios: { infoPlist: { "CFBundleURLTypes": [ { "CFBundleTypeRole": "Editor", "CFBundleURLName": env.ios.bundleIdentifier, "CFBundleURLSchemes": [env.firebase.recaptchaUrlScheme], }, ], }, }, // -- plugins -- plugins: [ "@react-native-firebase/app", "@react-native-firebase/auth", "@config-plugins/android-jsc-intl", [ "expo-build-properties", { "ios": { "useFrameworks": "static", }, }, ], ], }); // -- env -- const dev = { ios: { bundleIdentifier: "", googleServicesFile: "./config/firebase/ios/dev.plist", }, android: { package: "", googleServicesFile: "./config/firebase/android/dev.json", }, firebase: { recaptchaUrlScheme: "", }, }; ``` #### `./config/firebase/ios/dev.plist` (downloaded from the firebase console) ```xml CLIENT_ID omitted REVERSED_CLIENT_ID omitted ANDROID_CLIENT_ID omitted API_KEY omitted GCM_SENDER_ID omitted PLIST_VERSION 1 BUNDLE_ID bundle-id-dev PROJECT_ID omitted STORAGE_BUCKET omitted IS_ADS_ENABLED IS_ANALYTICS_ENABLED IS_APPINVITE_ENABLED IS_GCM_ENABLED IS_SIGNIN_ENABLED GOOGLE_APP_ID omitted DATABASE_URL omitted ```

iOS

Click To Expand

#### `ios/Podfile`: - [x] I'm not using Pods - [x] I'm using Pods and my Podfile looks like: ```ruby # N/A ``` #### `AppDelegate.m`: ```objc // N/A ```


Android

Click To Expand

#### Have you converted to AndroidX? - [ ] my application is an AndroidX application? - [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility? - [ ] I am using the NPM package `jetifier` for react-native compatibility? #### `android/build.gradle`: ```groovy // N/A ``` #### `android/app/build.gradle`: ```groovy // N/A ``` #### `android/settings.gradle`: ```groovy // N/A ``` #### `MainApplication.java`: ```java // N/A ``` #### `AndroidManifest.xml`: ```xml ```


Environment

Click To Expand

**`react-native info` output:** ``` System: OS: macOS 12.6 CPU: (10) arm64 Apple M1 Pro Memory: 1.45 GB / 32.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.18.1 - /var/folders/92/txlg43592x9_m3sdv88ypvm40000gn/T/yarn--1675812696227-0.4644924613098871/node Yarn: 1.22.19 - /var/folders/92/txlg43592x9_m3sdv88ypvm40000gn/T/yarn--1675812696227-0.4644924613098871/yarn npm: 8.19.2 - ~/.asdf/plugins/nodejs/shims/npm Watchman: Not Found Managers: CocoaPods: 1.11.3 - /Users/ty/.asdf/shims/pod SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0 Android SDK: Not Found IDEs: Android Studio: 2021.3 AI-213.7172.25.2113.9123335 Xcode: 14.0.1/14A400 - /usr/bin/xcodebuild Languages: Java: 11.0.17 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.1.0 => 18.1.0 react-native: 0.70.5 => 0.70.5 react-native-macos: Not Found npmGlobalPackages: *react-native*: Not Found ``` - **Platform that you're experiencing the issue on**: - [x] iOS - [ ] Android - [x] **iOS** but have not tested behavior on Android - [ ] **Android** but have not tested behavior on iOS - [ ] Both - **`react-native-firebase` version you're using that has this issue:** - `16.4.6` - **`Firebase` module(s) you're using that has the issue:** - `Auth` - **Are you using `TypeScript`?** - `Y` & `4.9.3`


mikehardy commented 1 year ago

Hi there - most likely an invalid project config of some sort - triple-check entitlements and you may need to integrate messaging to make sure the APNS token used for iOS device verification goes through? Some ideas: https://stackoverflow.com/questions/45091583/invalid-token-when-trying-to-authenticate-phone-number-using-firebase

Please note this works for other uesrs, so you have a project-specific configuration issue and there likely won't be a way for us or anyone else to help you work through it

tycobbb commented 1 year ago

that seems like it might be the issue, thanks =).

thoth-seshat commented 9 months ago

I'm getting this same issue currently.