Reputation: 155
so i want to save a user object in firestore, it's my first time working with firestore, so i use Bcrypt to encode the password than i save the object in firestore but it doesn't seem to be able to save it
This is my code
* 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 });
});
});
};
and am getting this error
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)
Upvotes: 0
Views: 1854
Reputation: 599641
Most likely the hash is returns as a readable stream, in which case you can for example hex encode it with:
hashedPassword.toString("hex")
Upvotes: 1