简体   繁体   中英

How to connect Firebase emulator in Swift by using typescript?

I am developing Swift app connecting Firebase emulator in Typescript.

import SwiftUI
import Firebase
import FirebaseAuth
import FirebaseStorage
import FirebaseFirestore
import FirebaseFirestoreSwift
import FirebaseFunctions
import FirebaseFunctionsSwift

@main
struct HelloApp: App {
    
    init(){
        FirebaseApp.configure()
       
        //Auth
        Auth.auth().useEmulator(withHost:"localhost", port:9099)
        //Storage
        Storage.storage().useEmulator(withHost:"localhost", port:9199)
        //Firestore
        let settings = Firestore.firestore().settings
        settings.host = "localhost:8080"
        settings.isPersistenceEnabled = false
        settings.isSSLEnabled = false
        Firestore.firestore().settings = settings
        //Cloud Function
        Functions.functions().useEmulator(withHost: "http://localhost", port: 5001)
    }
    
    var body: some Scene {
        WindowGroup {
            MainContent()
        }
    }
}

I got this error. [Firebase/Firestore][I-FST000001] WatchStream (14ed17248) Stream error: 'Unknown: An internal error has occurred, print and inspect the error details for more information.

And logs file, I got this error expected an unsecured JWT, the emulator does not validate JWTs and IS NOT SECURE .

How should I fix those. Please teach me those. Thank you.

You can try and change the code by moving the Firestore.firestore().settings to right after calling FirebaseApp.configure() Also be sure that you still have to set the FIREBASE_AUTH_EMULATOR_HOST env variable to your localhost as the local host needs to be authorized as a Firebase user using the authorisation . Check for a similar example here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM