Open dharmykoya opened 5 years ago
what is the solution
problem with the hashPassword function
yes the hash function was the issue... so I hashed outside and pasted in the seed file
don't understand pls show me
I used the hashed function in another js file and console.log the result so I copied the result and pasted it in the seed file as a string
ok i get but is there not a better way to hash the password in the seed
Hashing outside the file still seems like a very unsatisfying solution. The generated hash might also be subject to change if the configuration of the hash function changes (for example number of salting rounds).
(Also the error message displayed by sequelize is not very useful to getting to the bottom of this error.)
Any better suggestions?
bump - why can't i use bcrypt in the seed files?
you can define hash password function in same seed file.
or can do this something like i did.
I'm also having a related issue. I think you can't use file imported from another place in seeding
'use strict';
const bcrypt = require('bcrypt');
const uuid = require('uuid');
const makePassword = (pw) => {
return new Promise(async rs => {
let salt, hash;
salt = await bcrypt.genSalt(10);
hash = await bcrypt.hash(pw, salt);
return rs(hash);
})
}
module.exports = {
up: async (queryInterface, Sequelize) => {
let password = await makePassword("abcABC123!@#");
return queryInterface.bulkInsert('Users', [{
id: uuid(),
firstName: 'John',
lastName: 'Doe',
email: 'admin@admin.com',
password,
createdAt: new Date(),
updatedAt: new Date()
}], {});
},
down: (queryInterface, Sequelize) => {
return queryInterface.bulkDelete('Users', null, {});
}
};
it worked with me
What you are doing?
./node_modules/.bin/sequelize db:seed:all
What do you expect to happen?
my seed data should be saved in the database
What is actually happening?
But the output was bar! == 20190303113530-user: migrating ======= ERROR: Unexpected identifier
Output, either JSON or SQL
Dialect: postgres Database version: Sequelize CLI version: "^5.4.0 Sequelize version: ^4.42.0