Firebase 函数 - admin.firestore() get() 在本地服务上引发身份验证错误

Ind*_*dhu 5 firebase firebase-admin google-cloud-firestore firebase-cli

我有一个 firebase 云函数,它从云 Firestore 获取数据。

const userSnapshot = await admin.firestore().collection('users').doc(user).get()
Run Code Online (Sandbox Code Playgroud)

当使用firebase emulators:start.

我收到以下错误:

The Cloud Firestore emulator is not running so database operations will fail with a 'default credentials' error.
?  Google API requested!
   - URL: "https://oauth2.googleapis.com/token"
   - Be careful, this may be a production service.
>  Auth error:Error: invalid_grant
Run Code Online (Sandbox Code Playgroud)

只有在更新 firebase-tools 后才会发生这种情况。以前使用firebase serve --only function --port=9000. 在此工具版本中,我无法通过命令行设置端口。

Ind*_*dhu 1

此问题已在 6.9.2 中解决

我们可以使用带有端口号的firebase服务来访问firestore。

https://github.com/firebase/firebase-tools/issues/1265