所以我想将用户对象保存在Firestore中,这是我第一次使用Firestore,所以我使用Bcrypt编码密码,而不是将对象保存在Firestore中,但似乎无法保存它。
这是我的代码
* createUser
* @param {string} email
* @param {string} password
* @param {string} name
*/
const createUser = async (email, password, name) => {
const user = await getUser(email);
if (user) throw new Error('User account already exists');
bcrypt.genSalt(10, (salt) => {
bcrypt.hash(password, salt, (hashedPassword) => {
db.collection('users')
.doc(email)
.set({ hashedPassword, email, name });
});
});
};
并且收到此错误
throw new Error(validate_1.customObjectMessage(arg, value, path));
^
Error: Value for argument "data" is not a valid Firestore document. Input is not a plain JavaScript object (found in field "hashedPassword").
at Object.validateUserInput (/home/abdessalem/Desktop/tutum/test/simple-auth-app/node_modules/@google-cloud/firestore/build/src/serializer.js:301:15)
at validateDocumentData (/home/abdessalem/Desktop/tutum/test/simple-auth-app/node_modules/@google-cloud/firestore/build/src/write-batch.js:620:22)
at WriteBatch.set (/home/abdessalem/Desktop/tutum/test/simple-auth-app/node_modules/@google-cloud/firestore/build/src/write-batch.js:234:9)
at DocumentReference.set (/home/abdessalem/Desktop/tutum/test/simple-auth-app/node_modules/@google-cloud/firestore/build/src/reference.js:340:14)
at /home/abdessalem/Desktop/tutum/test/simple-auth-app/src/firestore/index.js:54:10
at /home/abdessalem/Desktop/tutum/test/simple-auth-app/node_modules/bcrypt/bcrypt.js:140:13
at processTicksAndRejections (internal/process/task_queues.js:79:11)
[最有可能将散列返回为二进制,在这种情况下,您可以使用例如:用十六进制对其进行编码: