I can't get the result of a resolved promise inside the export default section.
Hi devs, I'm new to JavaScript and I'm having trouble with promises and export default section. I'm hashing a password but I can't get the value inside my users' array object. I can get the password on my console though, and I want to use that array in my controllers to populate it with other users using postman.
My userModel module that I'm importing in my controllers.
import hasher from '../helpers/password';
const adminPassword = async () =>{
const hashedPwd = await hasher.hashingPassword('john124', 10);
console.log(hashedPwd);
return hashedPwd;
};
export default [
{
id: 1,
first_name: 'john',
last_name: 'doe',
email: 'john@gmail.com',
password: adminPassword(),
address: 'kigali',
is_admin: true
}
]
Response body from Postman
{
"status": 200,
"message": "Successfully Signed Up",
"data": [
{
"id": 1,
"first_name": "john",
"last_name": "doe",
"email": "john@gmail.com",
"password": {},
"address": "kigali",
"is_admin": true
},
{
"id": 2,
"email": "james@gmail.com",
"first_name": "james",
"last_name": "mes",
"password": "$2a$10$XXCc4oMwawyWZMzJJdUyq.Z.l9YobO3jicg6x7qNN/v7.94c9qVg.",
"address": "kinshasa",
"is_admin": false
}
]
}
Console output
[ { id: 1,
first_name: 'john',
last_name: 'doe',
email: 'john@gmail.com',
password:
Promise {
'$2a$10$a575M8tm1b8QdkH./V0zSuxGUV43OapBzehXyH9CkpypqAr0hmsPK' },
address: 'kigali',
is_admin: true } ]
How can I get just the hashed string as my password? Thank you in advance.