# How can I detect first login after email verification

**URL:** <https://community.auth0.com/t/how-can-i-detect-first-login-after-email-verification/100442>\
**Category:** Get Help\
**Tags:** identifier-first, login-experience\
**Created:** [February 14, 2023, 8:08am UTC](https://community.auth0.com/t/how-can-i-detect-first-login-after-email-verification/100442 "2023-02-14T08:08:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ramazan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ramazan/32/33369_2.png) [@ramazan](https://community.auth0.com/u/ramazan)\
**Post date:** [February 14, 2023, 8:08am UTC](https://community.auth0.com/t/how-can-i-detect-first-login-after-email-verification/100442/1 "2023-02-14T08:08:17Z")

</div>

I want to assign app-token to my user. So, I need to detect first login after the email verification. How can ı implement this?

---

<div class="post-metadata">

**Author:** ![wayne.lim](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/wayne.lim/32/44587_2.png) [@wayne.lim](https://community.auth0.com/u/wayne.lim)\
**Post date:** [February 15, 2023, 5:04am UTC](https://community.auth0.com/t/how-can-i-detect-first-login-after-email-verification/100442/2 "2023-02-15T05:04:39Z")

</div>

Hello @ramazan ,

Do you mean retrieving access token whenever user logins? Whenever a user authenticates, an [access token](https://auth0.com/docs/secure/tokens/access-tokens/get-access-tokens#control-access-token-audience) which includes the target audience and scope of access will be returned.

Why do you have the need to detect first login after email verification?

Thanks!

---

<div class="post-metadata">

**Author:** ![ramazan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/ramazan/32/33369_2.png) [@ramazan](https://community.auth0.com/u/ramazan)\
**Post date:** [February 15, 2023, 5:01pm UTC](https://community.auth0.com/t/how-can-i-detect-first-login-after-email-verification/100442/3 "2023-02-15T17:01:47Z")

</div>

> [@wayne.lim](#):
>
> Do you mean retrieving access token whenever user logins? Whenever a user authenticates, an [access token](https://auth0.com/docs/secure/tokens/access-tokens/get-access-tokens#control-access-token-audience) which includes the target audience and scope of access will be returned.

Helloo,

As I mentioned above, if I can detect the first login after email verification, I will define the virtual credit that I created in the my app to the users.

So I don’t need to check every login. Instead I just need detect the first login after email verification.

---

<div class="post-metadata">

**Author:** ![wayne.lim](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/wayne.lim/32/44587_2.png) [@wayne.lim](https://community.auth0.com/u/wayne.lim)\
**Post date:** [February 16, 2023, 4:04am UTC](https://community.auth0.com/t/how-can-i-detect-first-login-after-email-verification/100442/4 "2023-02-16T04:04:44Z")

</div>

Hello @ramazan ,

Thanks for clarifying.  
You can detect first login by creating a Post login action and checking for [event.stats.login\_counts](https://auth0.com/docs/customize/actions/flows-and-triggers/login-flow/event-object).

For example, you can create a rule to detect first login (counts ===1) and assign app-token there.

```auto
exports.onExecutePostLogin = async (event, api) => {
  if(event.stats.logins_count === 1){
    //assign app-token here
  }else{
    //not first login
  }
};

```

This is quite similar to a use case in the Community and attaching for your reference.

> [@How to distinguish first login after sign up](https://community.auth0.com/t/how-to-distinguish-first-login-after-sign-up/94885/4):
>
> Post-Login Actions do occur for silent authentication requests. A reliable solution would be to see if stripe\_customer\_id already exists in the user app\_metadata object, and skip the action for the user if it does. However, if you need to rely on first logins only in the Post-Login Action flow instead, something like below might help // check if user has more than one login, or if this is a refresh token rotation, or a silent auth request const not\_first\_login = event.stats.logins\_count \> 1 |…

Let me know how it goes, thanks!

---

<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 2, 2023, 4:05am UTC](https://community.auth0.com/t/how-can-i-detect-first-login-after-email-verification/100442/5 "2023-03-02T04:05:39Z")

</div>

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