I'm working on creating a table of users using Bcrypt and keep getting an error:
(node:54133) UnhandledPromiseRejectionWarning: Error: Client was closed and is not queryable
I'm recycling some code from a previous project that is working on that project and not sure where I'm going wrong with it. Below is my test function sitting in my seed.js as well as the function it's calling. As far as I'm seeing it's hitting the helper function but then erroring out, when I console.log my fields in the helper function, I'm getting all the fields, but it's not inserting into my Postgres table.
Seed function
async function testUsers() {
try {
console.log("testing");
bcrypt.hash("bertie99", SALT_COUNT, async function (err, hashedPassword) {
console.log("71", err);
const starter = await createUser({
username: "userone",
password: hashedPassword,
email: "123@yahoo.com",
});
console.log(starter);
});
} catch (error) {
console.log(error);
}
}
Helper function
async function createUser({ username, password, email }) {
try {
console.log("email", email);
console.log("username", username);
console.log("password", password);
const result = await client.query(
`
INSERT INTO users(username, password, email)
VALUES ($1, $2, $3);
`,
[username, password, email]
);
return result;
} catch (error) {
throw error;
}
}