# How to check whether a Passwordless sign-in is a first-time sign in or not?

**URL:** <https://community.auth0.com/t/how-to-check-whether-a-passwordless-sign-in-is-a-first-time-sign-in-or-not/56327>\
**Category:** Get Help\
**Tags:** signup, passwordless\
**Created:** [January 17, 2021, 9:37am UTC](https://community.auth0.com/t/how-to-check-whether-a-passwordless-sign-in-is-a-first-time-sign-in-or-not/56327 "2021-01-17T09:37:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oded.magger](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/oded.magger/32/26240_2.png) [@oded.magger](https://community.auth0.com/u/oded.magger)\
**Post date:** [January 17, 2021, 9:37am UTC](https://community.auth0.com/t/how-to-check-whether-a-passwordless-sign-in-is-a-first-time-sign-in-or-not/56327/1 "2021-01-17T09:37:51Z")

</div>

I implemented a Passwordless connection with SMS, using Embedded Login on React Native.

On a User/Password DB connection, sign up and log in are two distinct API calls. On Passwordless, however, when a user signs in, an Auth0 user is created implicitly if no user previously existed for that phone number.

**Is it possible to know whether a Passwordless sign in is a ‘Sign Up’ or a ‘Log in with exisitng user’?**

The only solution I could think of was calling the User Management API to see if a user with this phone number exists, but I **really** want to avoid the additional API call, as well as the privacy and security risks derived from letting pre-authenticated end user pull data about existing users.

---

<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:** [January 19, 2021, 8:57pm UTC](https://community.auth0.com/t/how-to-check-whether-a-passwordless-sign-in-is-a-first-time-sign-in-or-not/56327/3 "2021-01-19T20:57:56Z")

</div>

Hi @oded.magger,

I am setting up a passwordless connection with SMS now to look into this.

Does your app need to know if the user is newly created after they log in or do you need to access this info elsewhere?

What SDK are you using?

---

<div class="post-metadata">

**Author:** ![oded.magger](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/oded.magger/32/26240_2.png) [@oded.magger](https://community.auth0.com/u/oded.magger)\
**Post date:** [January 19, 2021, 9:10pm UTC](https://community.auth0.com/t/how-to-check-whether-a-passwordless-sign-in-is-a-first-time-sign-in-or-not/56327/4 "2021-01-19T21:10:49Z")

</div>

Thank you for checking, @stephanie.chamblee !

I am using [GitHub - auth0/react-native-auth0: React Native toolkit for Auth0 API](https://github.com/auth0/react-native-auth0) .

Yes, the app needs to know if the user is newly created directly after login is successful.

---

<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:** [January 20, 2021, 1:16pm UTC](https://community.auth0.com/t/how-to-check-whether-a-passwordless-sign-in-is-a-first-time-sign-in-or-not/56327/5 "2021-01-20T13:16:44Z")

</div>

Ah okay! One way to accomplish this would be to add the user’s login count as a custom claim in the ID Token via a [Rule](https://auth0.com/docs/rules). The Rule has access to the user’s login count from the [Context Object](https://auth0.com/docs/rules/context-object).

To set this up, you can click on Rules from within your dashboard and click “+ CREATE RULE”. Select “Empty Rule”.

```auto
function (user, context, callback) {
  const namespace = 'https://YOUR_APP_DOMAIN/';
  const userType = context.stats && context.stats.loginsCount === 1 ? 'new' : 'existing';
  context.idToken[`${namespace}userType`] = userType;
  return callback(null, user, context);
}

```

When you [decode the ID Token](https://jwt.io/) the value of `namespace/userType` will be either “new” or “existing” based on their login count. You could alternatively include the login count as the custom claim if preferred by adjusting the code within the Rule.

```auto
function (user, context, callback) {
  const namespace = 'https://YOUR_APP_DOMAIN/';
  const loginCount = context.stats && context.stats.loginsCount ? context.stats.loginsCount : 0;
  context.idToken[`${namespace}loginCount`] = loginCount;
  return callback(null, user, context);
}

```

Here are docs about adding custom claims to ID Tokens: [Sample Use Cases: Scopes and Claims](https://auth0.com/docs/scopes/sample-use-cases-scopes-and-claims#add-custom-claims-to-a-token)

---

<div class="post-metadata">

**Author:** ![oded.magger](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/oded.magger/32/26240_2.png) [@oded.magger](https://community.auth0.com/u/oded.magger)\
**Post date:** [January 21, 2021, 4:35pm UTC](https://community.auth0.com/t/how-to-check-whether-a-passwordless-sign-in-is-a-first-time-sign-in-or-not/56327/6 "2021-01-21T16:35:19Z")

</div>

Thanks, @stephanie.chamblee ! Tested it and it works like a charm.

---

<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:** [February 5, 2021, 4:35pm UTC](https://community.auth0.com/t/how-to-check-whether-a-passwordless-sign-in-is-a-first-time-sign-in-or-not/56327/7 "2021-02-05T16:35:21Z")

</div>

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