即使部署成功,也不会触发 Firebase 功能来填充 Firestore 集合。为什么?
Firebase functions not triggered to populate Firestore collection, even when the deployment is successful. Why?
我想将一个新文档添加到我的用户集合中,该文档由 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。
好像我解析用户数据的方法不对,请指点我遗漏了什么?
函数日志:
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
更新:
我试过这个功能,它完成了工作:
exports.newUser = functions.auth.user().onCreate((user) => {
return db
.collection("user")
.doc(user.uid)
.set({
email: user.email,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
})
});
firebaser 在这里
据我所知,这个错误是最近引入到我们的 Functions SDK 中的。您可以在 Github 回购问题 #1102.
上查看其状态
我想将一个新文档添加到我的用户集合中,该文档由 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。
好像我解析用户数据的方法不对,请指点我遗漏了什么?
函数日志:
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
更新:
我试过这个功能,它完成了工作:
exports.newUser = functions.auth.user().onCreate((user) => {
return db
.collection("user")
.doc(user.uid)
.set({
email: user.email,
createdAt: new Date().toISOString(),
updatedAt: new Date().toISOString()
})
});
firebaser 在这里
据我所知,这个错误是最近引入到我们的 Functions SDK 中的。您可以在 Github 回购问题 #1102.
上查看其状态