[英]How to connect Firebase emulator in Swift by using typescript?
I am developing Swift app connecting Firebase emulator in Typescript.我正在开发 Swift 应用程序连接 Typescript 中的 Firebase 模拟器。
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
.和日志文件,我得到了这个错误
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 .您可以尝试通过在调用
FirebaseApp.configure()
之后将Firestore.firestore().settings
移动到右侧来尝试更改代码另外请确保您仍然必须将FIREBASE_AUTH_EMULATOR_HOST 环境变量设置为本地主机,因为本地主机需要获得授权作为 Firebase 用户使用授权。 Check for a similar example here 在此处检查类似示例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.