# Db login action script (postgresql) Unknown authenticationOk message

**URL:** <https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184>\
**Category:** Get Help\
**Created:** [June 15, 2022, 4:49pm UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184 "2022-06-15T16:49:45Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![bitsofinfo](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/bitsofinfo/32/38026_2.png) [@bitsofinfo](https://community.auth0.com/u/bitsofinfo)\
**Post date:** [June 15, 2022, 4:49pm UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184/1 "2022-06-15T16:49:46Z")

</div>

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 }”

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [June 24, 2022, 5:49pm UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184/3 "2022-06-24T17:49:40Z")

</div>

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?

> <https://github.com/brianc/node-postgres/issues/1508>
>
> With postgres 10.1 and SCRAM-SHA-256 password encryption enabled, node-postgres …driver throws the following error:
> 
> \`Error: Unknown authenticationOk message typeMessage { name: 'authenticationOk', length: 23 }\`
> 
> Not telling that encryption method is not supported or anything. It took a while to find out why my app is stopped working after i have changed the role name. I think there should be more verbose error for this case.

---

<div class="post-metadata">

**Author:** ![montassar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/montassar/32/33313_2.png) [@montassar](https://community.auth0.com/u/montassar)\
**Post date:** [June 27, 2022, 3:41pm UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184/4 "2022-06-27T15:41:13Z")

</div>

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

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

```

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [June 27, 2022, 4:14pm UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184/5 "2022-06-27T16:14:39Z")

</div>

Hi @montassar,

Are you seeing the exact same error as OP?

---

<div class="post-metadata">

**Author:** ![montassar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/montassar/32/33313_2.png) [@montassar](https://community.auth0.com/u/montassar)\
**Post date:** [June 27, 2022, 4:18pm UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184/6 "2022-06-27T16:18:08Z")

</div>

yes, it’s the same error :

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

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [June 27, 2022, 4:47pm UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184/7 "2022-06-27T16:47:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![montassar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/montassar/32/33313_2.png) [@montassar](https://community.auth0.com/u/montassar)\
**Post date:** [June 27, 2022, 4:55pm UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184/8 "2022-06-27T16:55:01Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![montassar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/montassar/32/33313_2.png) [@montassar](https://community.auth0.com/u/montassar)\
**Post date:** [June 27, 2022, 5:42pm UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184/9 "2022-06-27T17:42:13Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [June 27, 2022, 5:48pm UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184/10 "2022-06-27T17:48:43Z")

</div>

@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.

---

<div class="post-metadata">

**Author:** ![montassar](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/montassar/32/33313_2.png) [@montassar](https://community.auth0.com/u/montassar)\
**Post date:** [June 27, 2022, 7:37pm UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184/11 "2022-06-27T19:37:31Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [June 27, 2022, 7:51pm UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184/12 "2022-06-27T19:51:29Z")

</div>

Thanks for following up!

---

<div class="post-metadata">

**Author:** ![cooper6101](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cooper6101/32/40747_2.png) [@cooper6101](https://community.auth0.com/u/cooper6101)\
**Post date:** [October 21, 2022, 3:04am UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184/13 "2022-10-21T03:04:14Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![cooper6101](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/cooper6101/32/40747_2.png) [@cooper6101](https://community.auth0.com/u/cooper6101)\
**Post date:** [October 21, 2022, 2:02pm UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184/14 "2022-10-21T14:02:30Z")

</div>

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/](https://auth0-extensions.github.io/canirequire/)

I hope this helps solve someone else’s headache!

---

<div class="post-metadata">

**Author:** ![emb1](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/emb1/32/41592_2.png) [@emb1](https://community.auth0.com/u/emb1)\
**Post date:** [November 29, 2022, 8:59pm UTC](https://community.auth0.com/t/db-login-action-script-postgresql-unknown-authenticationok-message/85184/15 "2022-11-29T20:59:40Z")

</div>

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.](https://github.com/brianc/node-postgres)  
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
});

```

});

}
