I am trying to connect to my PostgresSQL database hosted on Heroku through Auth0’s Database Connections. I am following the postgresSQL template as closely as possible; however, I am getting an Error:
cb.apply is not a function
for my Create script.
Here is the script:
function create(user, callback) {
//this example uses the "pg" library
//more info here: https://github.com/brianc/node-postgres
const bcrypt = require('bcrypt');
const postgres = require('pg');
const conString = configuration.DATABASE_URL;
postgres.connect(conString, {ssl: { sslmode: 'require', rejectUnauthorized: false}}, function (err, client, done) {
if (err) return callback(err);
bcrypt.hash(user.password, 10, function (err, hashedPassword) {
if (err) return callback(err);
const query = 'INSERT INTO users(email, password) VALUES ($1, $2)';
client.query(query, [user.email, hashedPassword], function (err, result) {
// NOTE: always call `done()` here to close
// the connection to the database
done();
return callback(err);
});
});
});
}
I had to declare the sslmode in the postgres.connect because of this problem I was having with ssl.
It would be great if I can get help on where I can go from here.