我想在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