javascript Auth 0 Postgresql获取错误- this._connectionCallback不是函数

kqlmhetl  于 2023-01-04  发布在  Java
关注(0)|答案(2)|浏览(103)

我正在尝试将一个自定义数据库连接到auth0,并且正在使用他们的默认Postgres脚本。
我不知道为什么我得到以下错误:
此._connectionCallback不是函数
代码段中不存在connectionCallback。以下是“verify”代码段:

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);
    });
  });
}

感谢你的帮助。

mrwjdhj3

mrwjdhj31#

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);
    });
  });
}

测试检查此代码

2exbekwf

2exbekwf2#

我在这个线程中找到了解决方案-pg.connect not a function?
基本上,pg.connect已经被pg.Pool硬弃用了,如下所示:https://node-postgres.com/guides/upgrading
因此,函数代码现在如下所示:

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);
    });
  });
}

相关问题