Db login action script (postgresql) Unknown authenticationOk message

Hi.
I am trying a custom database login action script (against my postgresql db) using the template and getting the error:

the db is postgres 13.x

“Unknown authenticationOk message typeMessage { name: ‘authenticationOk’, length: 23 }”

  1. I verified the target postgres url + credential I am using to login work fine (from a separate client)

  2. using the "test’ feature on the login script page I get the error: “Unknown authenticationOk message typeMessage { name: ‘authenticationOk’, length: 23 }”

Hi @bitsofinfo,

This issue appears to be coming from pg. Can please share a code snippet of how you are authenticating (remove sensitive data)? Also have you looked at this thread?

hello dan,
it seems like i’m having the same problem with my login script.
this is the script i’m using :

function login(email, password, 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 = 'postgres://*****:*****@7.tcp.eu.ngrok.io:13176/postgres';
  postgres.connect(conString, function (err, client, done) {
    if (err) return callback(err);

    const query = 'SELECT id, name, email, password 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 || new WrongUsernameOrPasswordError(email));

      const user = result.rows[0];

      bcrypt.compare(password, user.password, function (err, isValid) {
        if (err || !isValid) return callback(err || new WrongUsernameOrPasswordError(email));

        return callback(null, {
          user_id: user.id,
          name: user.name,
          email: user.email
        });
      });
    });
  });
}

Hi @montassar,

Are you seeing the exact same error as OP?

yes, it’s the same error :

“Unknown authenticationOk message typeMessage { name: ‘authenticationOk’, length: 23 }”

Are you able to connect to the DB from another client?

hi dan,
i tried connecting from another client and it worked fine. seems like i have this problem only with auth0.

hello @dan.woda,
i tried working with ElephantSQL and everything worked fine with their DB url. It seems like the problem is with ngrok but i still can’t find a solution.

@montassar,

Have you been able to connect to the DB from a client that is external to your DB’s network? This error seems to be coming from the DB client, which suggests Auth0 has little control over it.

You could try running that same action script in a serverless function.

Hello @dan.woda,
I just fixed it !
Anyone having the same error and looking for a solution, it’s a problem related to your postgresql DB.
All you have to do is
1- open pg_hba.conf ( which is located under C:\Program Files\PostgreSQL\14\data ).
2- scroll down to the bottom of the file, there you will find at the end of every line “scram-sha-256”.
3- just change scram-sha-256 with trust, and that’s gonna fix your problem.

1 Like

Thanks for following up!

1 Like

Did anyone find a better fix for this? My db is in aws rds so altering the .conf file won’t work. Strangly my dev db is connecting fine but my prod db wont connect. inbound rules are good and I’m still getting this error. I have other connections to my db externally with no issues. Any help is much appreciated!

The solve for this is to require a newer pg version. auth0 is still using version 4 for some reason? Holy cow guys this needs an update.

` const { Client } = require(‘pg@8.7.1’);

const client = new Client({
user: configuration.DB_USERNAME,
password: configuration.DB_PASSWORD,
host: configuration.DB_HOSTNAME,
port: configuration.DB_PORT,
database: configuration.DB_NAME,
});

client.connect();
`

Then you can run client.query etc to get what you need done in the login script. pg 8.7.1 is the newest version according to auth0’s “can i require”

https://auth0-extensions.github.io/canirequire/

I hope this helps solve someone else’s headache!

2 Likes

Thank you, this was the issue for me.

function loginByEmail(email, callback) {
//this example uses the “pg” library
//more info here: GitHub - brianc/node-postgres: PostgreSQL client for node.js.
const { Client } = require(“pg@8.7.1”);
const connectionString = configuration.DB_CONNECTION_STRING;
const client = new Client({connectionString});
client.connect();

const query = “SELECT id, email FROM "User" WHERE email = $1”;
const values = [email];

client.query(query, [email], function (err, result) {
// NOTE: always call done() here to close
// the connection to the database
client.end();

if (err || result.rows.length === 0) return callback(err);

const user = result.rows[0];

return callback(null, {
  user_id: user.id,
  email: user.email
});

});

}