Firebase iOS 13 + emulators: Firestore SSL, hanging writes, duplicate anonymous users, param prompts
Four traps from wiring a SwiftUI app and TypeScript functions to the Firebase emulators. (1) In firebase-ios-sdk 13.2 Firestore.useEmulator(withHost:port:) only sets the host and leaves SSL on (see FIRFirestore.mm), so every write logs 'Ssl handshake failed (TSI_PROTOCOL_FAILURE)' and never completes; set settings.host, settings.isSSLEnabled = false and a memory cache by hand. Auth and Functions useEmulator work as documented. (2) try await document.setData(...) does not return while the client cannot reach the server, so never await a Firestore write inside a flow the user is waiting on; start it in an unstructured Task and let Firestore's queue deliver it. (3) Two callers doing currentUser ?? signInAnonymously() at launch each create an anonymous account; share one in-flight task (a small actor holding a Task) and check the Auth emulator's account list to confirm one user per fresh sign-in. Firebase keeps the user in the keychain across app deletion on the simulator, so add a debug signOut() switch to test first launch. (4) A defineString param with no value in functions/.env makes firebase emulators:exec (and deploy) stop at an interactive prompt, which looks like a hang in CI or an agent shell; put non-secret params in functions/.env and emulator stand-ins for secrets in a git-ignored functions/.secret.local. Use a demo- project id for automated emulator tests, but the real project id when the app connects, since the callable URL includes it.