Own database PostgresSQL no longer functionall

Hi, I was using my own database to store my users, I didn’t make any changes neither in Auth0 or on my DB, yet as of today all routes are displaying this error “postgres.connect is not a function” I think Auth0 for some reason updated the pg package and the example they use for setting it up does no longer work.

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://user:pass@localhost/mydb';
  postgres.connect(conString, function (err, client, done) {
    if (err) return callback(err);

    const query = 'SELECT id, nickname, email FROM users 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,
        nickname: user.nickname,
        email: user.email
      });
    });
  });
}

Its there a way to specify a pg version?

To clarify:
I fixed it using that code on the bottom, yet I would like to still specify a pg version so I don’t have to go and change every single project I got any time a pg update comes on.

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

  conString.connect((err, client) => {

I would like to still specify a pg version so I don’t have to go and change every single project I got any time a pg update comes on.

For Auth0 Node.js sandboxes, you can specify the version using the package-name@x.y.z format:

const { Client } = require("pg@8.7.1");

Auth0 only provides very specific versions for Node.js modules with 8.7.1 being the latest version available. If you want to use older versions on Auth0 sandbox environments, they are documented on Can I Require?.

1 Like

Teamwork makes the dreamwork, thanks everybody for sharing all that with the rest of community!