我想在firebase触发的用户集合中添加一个新文档.auth()但是数据库没有被填充.

这是我的firebase功能:

exports.newUser = functions.auth.user().onCreate((user) => {
    return db
        .collection("user")
        .doc(user.uid)
        .create(JSON.parse(JSON.stringify(user)));
});

这是我的注册方法:

export const register = (email, password) => dispatch => new Promise((resolve, reject) => {
    firebase.auth().createUserWithEmailAndPassword(email, password)
        .then(() => {
            resolve()
        })
        .catch(() => {
            console.log(typeof (email, password))
            reject()
        })
})

执行后,新用户将添加到身份验证中,但不会触发新文档的创建.函数newUser已成功部署到firebase.

似乎我解析用户数据的方法不正确,请建议我缺少什么?

功能日志(log):

4:38:51.935 PM outlined_flag
newUser Function execution started 4:38:52.968 PM newUser TypeError: entry.toJSON is not a function 4:38:52.968 PM newUser at /workspace/node_modules/firebase-functions/lib/common/providers/identity.js:113:70 4:38:52.968 PM newUser at Array.map () 4:38:52.968 PM newUser at Object.record.toJSON (/workspace/node_modules/firebase-functions/lib/common/providers/identity.js:113:49) 4:38:52.968 PM newUser at JSON.stringify () 4:38:52.968 PM newUser at /workspace/index.js:10:33 4:38:52.968 PM newUser at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:135:23) 4:38:52.968 PM newUser at /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/function_wrappers.js:144:25 4:38:52.968 PM newUser at processTicksAndRejections (node:internal/process/task_queues:96:5) 4:38:52.968 PM newUser TypeError: entry.toJSON is not a function 4:38:52.968 PM newUser at /workspace/node_modules/firebase-functions/lib/common/providers/identity.js:113:70 4:38:52.968 PM newUser at Array.map () 4:38:52.968 PM newUser at Object.record.toJSON (/workspace/node_modules/firebase-functions/lib/common/providers/identity.js:113:49) 4:38:52.968 PM newUser at JSON.stringify () more_vert 4:38:52.968 PM newUser at /workspace/index.js:10:33 4:38:52.968 PM newUser at cloudFunction (/workspace/node_modules/firebase-functions/lib/cloud-functions.js:135:23) 4:38:52.968 PM newUser at /layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/function_wrappers.js:144:25 4:38:52.968 PM newUser at processTicksAndRejections (node:internal/process/task_queues:96:5) 4:38:52.979 PM outlined_flag
newUser Function execution took 1044 ms. Finished with status: error

推荐答案

firebaser here

据我所知,这个bug最近被引入了我们的函数SDK.你可以在Github回购第#1102期上查看它的状态.

Node.js相关问答推荐

Node.js promise 循环中的所有多个API调用

如何使用Node.js、Express和Mongoose创建多个API

如何使用NodeJS处理来自请求的单个或多个文件?

如何在不丢失其他键的情况下解开子文档数组,然后反转该过程?

"sh:/usr/local/bin/node:当它存在于文件目录中时未找到

未显示NPM版本

Mongoose post中间件触发deleteMany

Nodejs 从链接数组中获取数据并保存到 mongodb

级联定时器和Jest 的异步功能

带有事件网格的 Azure 函数在没有 ngrok 的情况下在本地运行

使用 Node.js 在 MongoDB 中搜索

Node.js 大文件上传到 MongoDB 阻塞了事件循环和工作池

为什么需要在 NodeJS 应用程序中创建服务器?

带有 node.js 和 express 的基本网络服务器,用于提供 html 文件和assets资源

从 Node.js 应用程序查询 Heroku 托管的 Postgres 数据库时出现自签名证书错误

Sequelize 基于关联的查找

npm 出现无法读取依赖项错误

nodeJS - 如何使用 express 创建和读取会话

我应该如何在 webpack 中使用时刻时区?

在 Node.js 中获取终端的宽度