Im wondering how i can use the pgcrypt extension inside my Node.js application to hash my passwords when i insert a user into the database. Might be a simple solution, but i cant figure out how to use theese PG extensions inside applications...
As an example this is my query to create an admin table, and insert an admin to the table. Now i would like to hash the password.
function createAdmin(){
var usertypeid = null;
const type = "adm";
pool.query(`INSERT INTO usertype(type) VALUES ($1) RETURNING userTypeId;`, [type], function (error, results) {
if (error){
throw error;
} else{
usertypeid = results.rows[0].usertypeid;
console.log(usertypeid);
insertAdmin();
}
});
function insertAdmin(){
pool.query(`
INSERT INTO users(
usertypeid, userName, email, password)
VALUES($1, 'admin', '[email protected]', crypt('admin'), gen_salt('bf'));`, [usertypeid]);
}
}