# User verification with custom db connection

**URL:** <https://community.auth0.com/t/user-verification-with-custom-db-connection/78324>\
**Category:** Get Help\
**Tags:** actions, custom-db, verify-email\
**Created:** [February 15, 2022, 9:39pm UTC](https://community.auth0.com/t/user-verification-with-custom-db-connection/78324 "2022-02-15T21:39:29Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lighthousen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lighthousen/32/30160_2.png) [@lighthousen](https://community.auth0.com/u/lighthousen)\
**Post date:** [February 15, 2022, 9:39pm UTC](https://community.auth0.com/t/user-verification-with-custom-db-connection/78324/1 "2022-02-15T21:39:29Z")

</div>

We’re using a custom db connection for our Auth0 user store. We’ve got a pretty basic Verify action script that updates a flag in our database. The script executes just fine, data is updated, everyone is happy. However, the user email is still showing as pending within Auth0. The only way to change `Pending` to `Active` is to log out, and then log back in. Is this normal behavior, or is something wrong?

---

<div class="post-metadata">

**Author:** ![lihua.zhang](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lihua.zhang/32/39683_2.png) [@lihua.zhang](https://community.auth0.com/u/lihua.zhang)\
**Post date:** [February 16, 2022, 1:44am UTC](https://community.auth0.com/t/user-verification-with-custom-db-connection/78324/3 "2022-02-16T01:44:20Z")

</div>

Hi @lighthousen,

Welcome to Auth0 Community!

We are looking into this query and will get back to you soon.

---

<div class="post-metadata">

**Author:** ![lihua.zhang](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lihua.zhang/32/39683_2.png) [@lihua.zhang](https://community.auth0.com/u/lihua.zhang)\
**Post date:** [February 16, 2022, 11:34pm UTC](https://community.auth0.com/t/user-verification-with-custom-db-connection/78324/4 "2022-02-16T23:34:58Z")

</div>

Have you included the email\_verified: true in the Login function? Here is the sample scripts.

```auto
function login(email, password, callback) {
  ...
  const profile = {
    user_id: externaldb|12345,
    email: joe.schmo@externaldb.com,
    email_verified: true
  };
  callback(null, profile);
}

```

If this is already added to your Login function and is not working correctly. Could you provide your function?

---

<div class="post-metadata">

**Author:** ![lighthousen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lighthousen/32/30160_2.png) [@lighthousen](https://community.auth0.com/u/lighthousen)\
**Post date:** [February 17, 2022, 7:52pm UTC](https://community.auth0.com/t/user-verification-with-custom-db-connection/78324/5 "2022-02-17T19:52:19Z")

</div>

Thanks for the reply! Sorry for the delayed response, the notification went to spam.

Here is my login script:

```auto
function login(email, password, callback) {
  ...
  callback(null, {
            user_id: user.id.toString(),
            nickname: user.nickname,
            email: user.email,
            email_verified: (user.state === 'A' ? true: false),
            app_metadata: {
              v2_role: user.role 
            },
  });

```

`email_verified` depends on the state flag that comes in from our database. The verification database action script flips the state from pending to active. The login script is working fine when logging in / out.

---

<div class="post-metadata">

**Author:** ![lighthousen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lighthousen/32/30160_2.png) [@lighthousen](https://community.auth0.com/u/lighthousen)\
**Post date:** [February 21, 2022, 2:20pm UTC](https://community.auth0.com/t/user-verification-with-custom-db-connection/78324/6 "2022-02-21T14:20:08Z")

</div>

Just checking if you saw this @lihua.zhang . Thanks!

---

<div class="post-metadata">

**Author:** ![lihua.zhang](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lihua.zhang/32/39683_2.png) [@lihua.zhang](https://community.auth0.com/u/lihua.zhang)\
**Post date:** [March 4, 2022, 8:54pm UTC](https://community.auth0.com/t/user-verification-with-custom-db-connection/78324/7 "2022-03-04T20:54:42Z")

</div>

Hi @lighthousen ,

Thank you for providing your login script. And sorry about the delay.

The database action scripts can be triggered only once when the user attempts to login.That’s why after the “Verify” scripts are executed, they have to log out and log in again to trigger the “Login” script which updates the email\_verified to true.

If I understand correctly, you want to allow only the verified user to login.

In that case, I suggest you use an Auth0 Post-Login Action to accomplish this, instead of updating the flag in the database in the Verified script and check the flags in the Login script.

[This article](https://auth0.com/docs/customize/actions/write-your-first-action#create-an-action) explained the steps to create such an action.

Here is a snippet of the sample scripts for this action.

```auto
exports.onExecutePostLogin = async (event, api) => {
  if (!event.user.email) {
    api.access.deny(`Please verify your email address to continue to ${event.client.name}`);
  }
};

```

Basically, it will deny users access until they have verified their email, and you can guarantee the scripts will set the user’s `email_verified: true` correctly.

Hope this helps!

---

<div class="post-metadata">

**Author:** ![lighthousen](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/lighthousen/32/30160_2.png) [@lighthousen](https://community.auth0.com/u/lighthousen)\
**Post date:** [March 11, 2022, 10:08pm UTC](https://community.auth0.com/t/user-verification-with-custom-db-connection/78324/8 "2022-03-11T22:08:11Z")

</div>

Thank you for the help. It does clarify things, but not completely what I’m after. We’re fine with allowing users to be signed in before email confirmation. We simply restrict access based on whether or not they’ve verified.

I would like to not only flip the flag in our own database, but also within Auth0 when the user clicks on the verification link. That way if they are signed in already, they will receive elevated permissions because they’ve verified the email address. Based on your latest reply, maybe that is not possible.

One thing I noticed is that when the link is clicked on, the flag is flipped in our database, but the user is given an error saying the code was invalid. One thing I noticed is the documentation says to provide a JSON object with user details if the first parameter is NULL for the callback. [Verify Script Templates](https://auth0.com/docs/authenticate/database-connections/custom-db/templates/verify#callback-example). However, none of the examples following that seem to follow that. Maybe that is the issue?

---

<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:** [March 26, 2022, 10:08pm UTC](https://community.auth0.com/t/user-verification-with-custom-db-connection/78324/9 "2022-03-26T22:08:57Z")

</div>

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