简体   繁体   中英

Auth0 Postgresql getting error - this._connectionCallback is not a function

I am trying to connect a custom database to auth0 and am using their default Postgres script.

I can't figure out why I am getting the following error:

this._connectionCallback is not a function

connectionCallback doesn't exist in the snippet. Here's the 'verify' snippet:

function verify (email, callback) {
  //this example uses the "pg" library

  const { Client } = require("pg");
  const conString = new 
  Client({connectionString:'postgresql://postgres:password@database:port/host'});

  conString.connect(conString, function (err, client, done) {
    if (err) return callback(err);

    const query = 'UPDATE auth_user SET email_Verified = true WHERE email_Verified = false AND email = $1';
    client.query(query, [email], function (err, result) {
      done();

      return callback(err, result && result.rowCount > 0);
    });
  });
}

Appreciate any help with this.

 function verify (email, callback) { //this example uses the "pg" library const { Client } = require("pg"); const conString = new Client({connectionString:'postgresql://postgres:password@database:port/host'}); conString.connect(conString, function (err, client, done) { if (err) { console.log(err); return callback(err); } const query = 'UPDATE auth_user SET email_Verified = true WHERE email_Verified = false AND email = $1'; client.query(query, [email], function (err, result) { done(); console.log(err); return callback(err, result && result.rowCount > 0); }); }); }

for test check this code

I found the solution in this thread - pg.connect not a function?

Basically, pg.connect has been hard-deprecated in favor of pg.Pool, as documented here: https://node-postgres.com/guides/upgrading

So the functional code now looks like this:

function verify (email, callback) {

  const bcrypt = require('bcrypt');
  const pg = require("pg");
  var pool = new pg.Pool({
        user: '**',
        host: '**',
        database: '**',
        password: '**',
        port: **,
  });

  pool.connect(function (err, client, done) {
    if (err) 
      console.log('error');
    { console.log(err); return callback(err); }

    const query = 'UPDATE auth_user SET email_Verified = true WHERE email_Verified = false AND email = $1';
    client.query(query, [email], function (err, result) {
      done();
console.log(err);
      return callback(err, result && result.rowCount > 0);
    });
  });
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM