有人可以协助解决此错误吗?我已经看到了类似的答案:“ Firebase Firestore云功能显示错误:无效地使用类型“ undefined”作为Firestore参数”,但是该答案无济于事。
Error: Invalid use of type "function" as a Firestore argument.
at Object.customObjectError (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/validate.js:168:16)
at Serializer.encodeValue (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/serializer.js:146:26)
at Serializer.encodeFields (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/serializer.js:54:34)
at Serializer.encodeValue (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/serializer.js:139:44)
at Serializer.encodeValue (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/serializer.js:124:38)
at Serializer.encodeFields (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/serializer.js:54:34)
at Function.fromObject (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/document.js:77:53)
at WriteBatch.set (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/write-batch.js:245:54)
at DocumentReference.set (/user_code/node_modules/firebase-admin/node_modules/@google-cloud/firestore/build/src/reference.js:349:27)
at exports.userSignupData.functions.auth.user.onCreate (/user_code/lib/userSignupData.js:9:20
该功能在ionic 4应用程序中使用:
import * as functions from "firebase-functions";
import * as admin from "firebase-admin";
admin.initializeApp();
const db = admin.firestore();
export const userSignupData = functions.auth.user().onCreate((user, context) => {
const userRef = db.doc(`users/${user.uid}`);
return userRef.set({
id: user.uid,
createdAt: context.timestamp,
signupEmail: user.email,
emailVerified: user.email,
originalSigninProvider: user.providerData
});
});
答案 0 :(得分:0)
firebase似乎不喜欢set对象中的重复属性调用。
signupEmail: user.email,
emailVerified: user.email,
答案 1 :(得分:0)
在您要上传的数据中,context.timestamp
可能是函数类型,这意味着您试图将函数而不是有效的“日期”或“时间戳”推送到firestore。
根据this thread on creating timestamps in firestore,您可以传递截至 2019年2月的有效时间戳,例如:
firestore().collection("item")
.add({...item, created: firebase.firestore.Timestamp.fromDate(new Date()) })