firebase-ios-sdk: Switching from emulator to Firestore results in Unauthenticated error on device and simulator
[REQUIRED] Step 1: Describe your environment
Xcode version: 13.2.1 Firebase SDK version: Firebase (8.12.1) Installation method: SPM Firebase Component: Functions [REQUIRED] Step 2: Describe the problem
My problem is calling a callable function. Using the emulator (DEBUG) everything works fine in my iOS app. However, as soon as I switch to regular Firestore (QA) I get the following error:
Error Domain=com.firebase.functions Code=16 “UNAUTHENTICATED” UserInfo={NSLocalizedDescription=UNAUTHENTICATED}
There are no logs from the emulator when the error is returned so i am guessing the request doesn’t even reach the function. This issue seems to be related to this issue, at least I think it is. (#7783 )
Steps to reproduce:
Start emulators Start ios app with emulators configured call the callable function - this works switch from the emulator to Firestore - this does not work Actual result: fails with error: Unauthenticated.
Expected result: The callable function is executed successfully.
Relevant Code:
(Swift)
Inside AppDelegate
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
#if targetEnvironment(simulator)
let providerFactory = AppCheckDebugProviderFactory()
#else
let providerFactory = MyAppCheckProviderFactory()
#endif
AppCheck.setAppCheckProviderFactory(providerFactory)
#if DEBUG
print("_________DEBUG___________")
FirebaseApp.configure()
let db = Firestore.firestore()
//This is for testing
Auth.auth().useEmulator(withHost:"localhost", port:9099)
Functions.functions().useEmulator(withHost: "localhost", port: 5001)
let settings = db.settings
settings.host = "localhost:8080"
settings.isPersistenceEnabled = false
settings.isSSLEnabled = false
db.settings = settings
//This is for testing
#else
print("__________QA______________")
FirebaseApp.configure()
let db = Firestore.firestore()
let settings = db.settings
settings.isPersistenceEnabled = true
db.settings = settings
#endif
Inside a class that uses callable functions to setup a user after anonymous signin
Functions.functions().httpsCallable("setupUser").call(dictToSubmit) { (result, error) in
Here the log that gets produced
2022-02-27 11:07:35.095163+0100 GameOn[67751:5263840] 8.12.1 - [Firebase/Auth][I-AUT000002] Token auto-refresh enabled.
2022-02-27 11:07:35.095841+0100 GameOn[67751:5263840] 8.12.1 - [Firebase/Auth][I-AUT000004] Token auto-refresh scheduled in 55:00 for the new token.
2022-02-27 11:07:35.096272+0100 GameOn[67751:5263840] 8.12.1 - [Firebase/Auth][I-AUT000017] Has valid access token. Estimated expiration date: 2022-02-27 11:07:34 +0000, current date: 2022-02-27 10:07:35 +0000
2022-02-27 11:07:35.177849+0100 GameOn[67751:5263857] [boringssl] boringssl_metrics_log_metric_block_invoke(151) Failed to log metrics
Something went wrong: Error Domain=com.firebase.functions Code=16 "UNAUTHENTICATED" UserInfo={NSLocalizedDescription=UNAUTHENTICATED}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 20 (9 by maintainers)
Thanks for the hint. I will open up a ticket and see if they can figure it out. Thanks for all the support!
Based on your implementation this does not seem to be a regression. I’ll try to reproduce it locally and investigate from there.
It looks like a functions issue, I can investigate if it turns out to be false.