# User can sign in before email confirmation

**URL:** <https://community.auth0.com/t/user-can-sign-in-before-email-confirmation/62730>\
**Category:** Get Help\
**Tags:** password, email-template, signup, email-verification, verification-email\
**Created:** [May 13, 2021, 11:30am UTC](https://community.auth0.com/t/user-can-sign-in-before-email-confirmation/62730 "2021-05-13T11:30:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![monika.prakash](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/monika.prakash/32/13482_2.png) [@monika.prakash](https://community.auth0.com/u/monika.prakash)\
**Post date:** [May 13, 2021, 11:30am UTC](https://community.auth0.com/t/user-can-sign-in-before-email-confirmation/62730/1 "2021-05-13T11:30:36Z")

</div>

Hi

I created a user. and I got the verification email.( verification email(using link) template.  
then before I validating the email. I tries to sign up using the email and password. and user sign in successfully. I think we need to verify the email for sign in ?

 ![emailprovider](https://global.discourse-cdn.com/auth0/original/3X/f/d/fdbddf36fbff4876ecca37affeb86d831da8ae73.png) i set my email provider like this.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 13, 2021, 12:09pm UTC](https://community.auth0.com/t/user-can-sign-in-before-email-confirmation/62730/3 "2021-05-13T12:09:52Z")

</div>

Hi @monika.prakash,

Thanks for joining the Community!

By default, users can log in to an app without verifying their email, however, the user’s `email_verified` attribute will be false until they confirm their email address:

```auto
{
    "user_id": "auth0|507f1f77bcf86cd799439020",
    "email": "john.doe@gmail.com",
    "email_verified": false // <-- this attribute will be false until user verfies email
}

```

In order to require email verification, you can use a [post-login Action](https://auth0.com/docs/actions/triggers/post-login):

```auto
exports.onExecutePostLogin = async (event, api) => {
  if (!event.user.email_verified) {
    api.access.deny(`Please verify your email before logging in.`);
  }
};

```

Until the user verifies their email, they will be redirected back to your app with an authorization error. The error message is passed as a query string param so that your app can display a user-friendly error:

```auto
http://exaample.com/?error=access_denied&error_description=Please%20verify%20your%20email%20before%20logging%20in.

```

Here is documentation on how to write an Action for your Auth0 tenant:

> **[Write Your First Action](https://auth0.com/docs/customize/actions/write-your-first-action)**
>
> Learn how to write an Action, which includes choosing a flow, creating an Action and configuring it, and binding it to the flow.

---

<div class="post-metadata">

**Author:** ![monika.prakash](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/monika.prakash/32/13482_2.png) [@monika.prakash](https://community.auth0.com/u/monika.prakash)\
**Post date:** [May 14, 2021, 10:40am UTC](https://community.auth0.com/t/user-can-sign-in-before-email-confirmation/62730/4 "2021-05-14T10:40:32Z")

</div>

HI @stephanie.chamblee

I tried this and but user can able to login . not created authentication error.

---

<div class="post-metadata">

**Author:** ![stephanie.chamblee](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/stephanie.chamblee/32/26087_2.png) [@stephanie.chamblee](https://community.auth0.com/u/stephanie.chamblee)\
**Post date:** [May 14, 2021, 12:19pm UTC](https://community.auth0.com/t/user-can-sign-in-before-email-confirmation/62730/5 "2021-05-14T12:19:52Z")

</div>

Hi @monika.prakash,

I took a look at your tenant’s action, and the code looks correct. However, it looks like at the moment the action is not placed into the post-login flow yet. Have you tested this with the action set?

> **[Write Your First Action](https://auth0.com/docs/customize/actions/write-your-first-action)**
>
> Learn how to write an Action, which includes choosing a flow, creating an Action and configuring it, and binding it to the flow.

Alternatively, you can use a rule:

```auto
function emailVerified(user, context, callback) {
  if (!user.email_verified) {
    return callback(new UnauthorizedError('Please verify your email before logging in.'));
  } else {
    return callback(null, user, context);
  }
}

```

---

<div class="post-metadata">

**Author:** ![monika.prakash](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/monika.prakash/32/13482_2.png) [@monika.prakash](https://community.auth0.com/u/monika.prakash)\
**Post date:** [May 18, 2021, 1:14pm UTC](https://community.auth0.com/t/user-can-sign-in-before-email-confirmation/62730/6 "2021-05-18T13:14:11Z")

</div>

Hi @stephanie.chamblee

Thank you 🙂  
its working

---

<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:** [June 2, 2021, 1:14pm UTC](https://community.auth0.com/t/user-can-sign-in-before-email-confirmation/62730/7 "2021-06-02T13:14:55Z")

</div>

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