# Custom database login

**URL:** <https://community.auth0.com/t/custom-database-login/128653>\
**Category:** Get Help\
**Tags:** custom-database-connections, connections\
**Created:** [February 29, 2024, 8:27pm UTC](https://community.auth0.com/t/custom-database-login/128653 "2024-02-29T20:27:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hacosta](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/hacosta/32/55301_2.png) [@hacosta](https://community.auth0.com/u/hacosta)\
**Post date:** [February 29, 2024, 8:27pm UTC](https://community.auth0.com/t/custom-database-login/128653/1 "2024-02-29T20:27:19Z")

</div>

Hi I have set a custom database with an action script on the login event this is the code:

```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 = 'user://password:@host/database';
  var pool = new postgres.Pool({connectionString: conString});
  pool.connect(function (err, client, done) {
    if (err) return callback(err);

    const query = 'SELECT id, name, email, encrypted_password, handle 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.encrypted_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,
          handle: user.handle
        });
      });
    });
  });
}

```

When I use the `try connection` feature or the test on the custom database with a user and password stored on the db given on the connection string, it works oka and return the token with the user data, but If i try to loging to my spa app that I setted up connection with the custom db as a source, I can’t logging with the same user and password.

Shuld the user/password beeing able to login to my spa application ? Or maybe I missing something.

---

<div class="post-metadata">

**Author:** ![dawid.matuszczyk](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dawid.matuszczyk/32/74550_2.png) [@dawid.matuszczyk](https://community.auth0.com/u/dawid.matuszczyk)\
**Post date:** [March 28, 2024, 11:11pm UTC](https://community.auth0.com/t/custom-database-login/128653/2 "2024-03-28T23:11:55Z")

</div>

Hi @hacosta

Welcome to the Auth0 Community!

Thank you for posting your question and I appreciate your patience. I’ve checked your tenant configuration and your SPA application is not enabled for custom database connection. To do that go to Authentication → Database → Application and change from grey to green switch button.

I hope it will help you!

Thanks  
Dawid

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [April 11, 2024, 11:12pm UTC](https://community.auth0.com/t/custom-database-login/128653/3 "2024-04-11T23:12:35Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
