# Error cb.apply is not a function from PostgresSQL Database Action Script Template

**URL:** <https://community.auth0.com/t/error-cb-apply-is-not-a-function-from-postgressql-database-action-script-template/89993>\
**Category:** Get Help\
**Tags:** postgresql, signup, custom-database, auth0\
**Created:** [September 5, 2022, 3:26am UTC](https://community.auth0.com/t/error-cb-apply-is-not-a-function-from-postgressql-database-action-script-template/89993 "2022-09-05T03:26:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jfletcher](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jfletcher/32/30511_2.png) [@jfletcher](https://community.auth0.com/u/jfletcher)\
**Post date:** [September 5, 2022, 3:26am UTC](https://community.auth0.com/t/error-cb-apply-is-not-a-function-from-postgressql-database-action-script-template/89993/1 "2022-09-05T03:26:45Z")

</div>

I am trying to connect to my PostgresSQL database hosted on Heroku through Auth0’s Database Connections. I am following the postgresSQL template as closely as possible; however, I am getting an Error:

> cb.apply is not a function

for my Create script.

Here is the script:

```auto
function create(user, 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 = configuration.DATABASE_URL;
  postgres.connect(conString, {ssl: { sslmode: 'require', rejectUnauthorized: false}}, function (err, client, done) {
    if (err) return callback(err);

    bcrypt.hash(user.password, 10, function (err, hashedPassword) {
      if (err) return callback(err);

      const query = 'INSERT INTO users(email, password) VALUES ($1, $2)';
      client.query(query, [user.email, hashedPassword], function (err, result) {
        // NOTE: always call `done()` here to close
        // the connection to the database
        done();

        return callback(err);
      });
    });
  });
}

```

I had to declare the sslmode in the postgres.connect because of [this](https://stackoverflow.com/questions/73603214/connecting-to-heroku-postgres-from-auth0-results-in-err-no-pg-hba-conf-entry-fo) problem I was having with ssl.

It would be great if I can get help on where I can go from here.

---

<div class="post-metadata">

**Author:** ![jfletcher](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jfletcher/32/30511_2.png) [@jfletcher](https://community.auth0.com/u/jfletcher)\
**Post date:** [September 13, 2022, 12:35am UTC](https://community.auth0.com/t/error-cb-apply-is-not-a-function-from-postgressql-database-action-script-template/89993/2 "2022-09-13T00:35:00Z")

</div>

I was able to get help by opening a ticket and what resolved the issue was declaring the version number of pg as well as updating the template. Here is the code that worked for me (Note that my table is named organizations)

```auto
function create(user, callback) {
  //this example uses the "pg" library
  //more info here: https://github.com/brianc/node-postgres

  const bcrypt = require('bcrypt');
  const postgres = require('pg@8.7.1');

  const conString = configuration.DATABASE_URL;
  const client = new postgres.Client( {
    connectionString: conString,
    ssl: {sslmode: 'require', rejectUnauthorized: false}
  });
  client.connect();
  
  bcrypt.hash(user.password, 10, function (err, hashedPassword) {
    if (err) return callback(err);

    const query = 'INSERT INTO organizations(email, password) VALUES ($1, $2)';
    client.query(query, [user.email, hashedPassword], function (err, result) {
      // NOTE: always call `done()` here to close
      // the connection to the database
      client.end();

      return callback(err);
    });
  });
}

```

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [November 4, 2022, 2:04pm UTC](https://community.auth0.com/t/error-cb-apply-is-not-a-function-from-postgressql-database-action-script-template/89993/3 "2022-11-04T14:04:58Z")

</div>

Thanks for sharing that with the rest of community!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [November 4, 2022, 2:05pm UTC](https://community.auth0.com/t/error-cb-apply-is-not-a-function-from-postgressql-database-action-script-template/89993/4 "2022-11-04T14:05:01Z")

</div>


