Node.js 如何在firestore中存储哈希密码
所以我想在firestore中保存一个用户对象,这是我第一次使用firestore,所以我使用Bcrypt对密码进行编码,而不是将对象保存在firestore中,但它似乎无法保存它 这是我的代码Node.js 如何在firestore中存储哈希密码,node.js,firebase,express,google-cloud-firestore,bcrypt,Node.js,Firebase,Express,Google Cloud Firestore,Bcrypt,所以我想在firestore中保存一个用户对象,这是我第一次使用firestore,所以我使用Bcrypt对密码进行编码,而不是将对象保存在firestore中,但它似乎无法保存它 这是我的代码 * createUser * @param {string} email * @param {string} password * @param {string} name */ const createUser = async (email, password, name) => {
* 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)
最有可能的是散列以可读流的形式返回,在这种情况下,您可以使用以下代码对其进行十六进制编码:
hashedPassword.toString("hex")
您可能需要将hashedPassword转换为Firestore可以接受的内容,例如Blob@我怎么能做到我不知道。这听起来像是你可以通过研究你正在使用的库提供的API来研究的东西。