I want to custom my postgres database to check email and password for login. but i am try to use the samples scripts to connect to custom database but i am getting error “postgres is not a function” then i click try button and fill the email and password .
Is this functionality only available in paid account or i can use in free account also for testing.
function loginByEmail(email, callback) {
//this example uses the "pg" library
//more info here: https://github.com/brianc/node-postgres
const postgres = require('pg');
const conString = 'postgres://usernam:pass@servername:5432/dbname?ssl=true';
postgres(conString, function (err, client, done) {
if (err) return callback(err);
const query = 'SELECT id, email FROM user WHERE email = $1';
client.query(query, [email], function (err, result) {
// NOTE: always call `done()` here to close
// the connection to the database
done();
if (err || result.rows.length === 0) return callback(err);
const user = result.rows[0];
return callback(null, {
user_id: user.id,
email: user.email
});
});
});
}
Please provide the code snippet that you use. Are you importing the required node package?
require('pg')
Is this functionality only available in paid account or i can use in free account also for testing.
Custom Databases require an Enterprise subscription, see Pricing - Auth0, even though it’s not hard blocked in lower subscription plans.
Update (after OP added code snippet):
@bloomjyotithakur: I think you’re probably not initializing postgres client correctly. Looking at an example here, it seems that you need to initialize like this:
const pg = require('pg');
const conString = 'postgres://usernam:pass@servername:5432/dbname?ssl=true';
const client = new pg.Client(conString);
client.connect();
const query = 'SELECT id, email FROM user WHERE email = $1';
client.query(query....
1 Like
OP added code snippet - what OP means
Thank you
OP = Original Poster (of this forum thread)
Did you try my code snippet, does it work?
i will try and let you know.
Please send complete snippet
“Request to Webtask got ESOCKETTIMEDOUT”
getting this error with @mathiasconradt you code
Is your postgres DB / server / port / firewall open for external requests (for Auth0 in particular)? And does the postgres DB allow for remote connections?
ok i will check and let you know