# Show error if chose unsupported location ( prefix of unsupported country)

**URL:** <https://community.auth0.com/t/show-error-if-chose-unsupported-location-prefix-of-unsupported-country/74957>\
**Category:** Get Help\
**Created:** [December 15, 2021, 1:57pm UTC](https://community.auth0.com/t/show-error-if-chose-unsupported-location-prefix-of-unsupported-country/74957 "2021-12-15T13:57:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nitzan.mazor](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nitzan.mazor/32/13374_2.png) [@nitzan.mazor](https://community.auth0.com/u/nitzan.mazor)\
**Post date:** [December 15, 2021, 1:57pm UTC](https://community.auth0.com/t/show-error-if-chose-unsupported-location-prefix-of-unsupported-country/74957/1 "2021-12-15T13:57:48Z")

</div>

Hi,  
we’re using auth-lock 11.24.0  
we are implementing passwordless login.

we are currently supporting only US users. is there a way to show error to the user in case submitting a location that is not US?

I know how to recognize the country location selection, but don’t know if there’s a way to initiate an error in specific cases like this.

I saw ‘Error Handling’ section here: [GitHub - auth0/lock: Auth0's signin solution](https://github.com/auth0/lock#customization)  
not sure if relevant, and if so, how to use.

will appreciate any input

thanks!

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [December 15, 2021, 11:05pm UTC](https://community.auth0.com/t/show-error-if-chose-unsupported-location-prefix-of-unsupported-country/74957/3 "2021-12-15T23:05:57Z")

</div>

Hi @nitzan.mazor,

Thanks for reaching out to the Auth0 Community!

I understand you’d like to restrict users from logging in and showing them an error when trying to log in from a country outside of the US.

To do so, you could use an [Auth0 Rule](https://auth0.com/docs/rules/examples#deny-access-based-on-a-condition) and check if the user is authenticating from a country outside of the _US_. If so, you can deny them access and provide them with a custom error message.

```auto
function (user, context, callback) {
  if (context.request.geoip.country_code !== "US") {
    return callback(new UnauthorizedError('Access to this application has been temporarily revoked'));
  }
  callback(null, user, context);
}

```

Once that is complete, you’ll be able to support only US users.

I hope this addresses your use case, and please let me know if you have any further questions.

Thank you.

---

<div class="post-metadata">

**Author:** ![nitzan.mazor](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nitzan.mazor/32/13374_2.png) [@nitzan.mazor](https://community.auth0.com/u/nitzan.mazor)\
**Post date:** [December 16, 2021, 7:51am UTC](https://community.auth0.com/t/show-error-if-chose-unsupported-location-prefix-of-unsupported-country/74957/4 "2021-12-16T07:51:20Z")

</div>

Hi @rueben.tiow ,

First of all thanks for your response!

Your code snippet might be very helpful for us also. I’m not sure I understand couple of things though:

1. Where should I write it exactly and when should it be called?
2. Where do I get user, context and callback from?

My second request is that other than restrict users by their geo location, I would like to restrict them by country prefix also.

To be clearer, if a user is outside the US, but signing in with a US number in a country we work with – it’s ok.

So I would like to pop an error if the member submits number that has prefix of a country that is not US.

Is this possible?

---

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [December 20, 2021, 4:28pm UTC](https://community.auth0.com/t/show-error-if-chose-unsupported-location-prefix-of-unsupported-country/74957/5 "2021-12-20T16:28:22Z")

</div>

Hi @nitzan.mazor,

Thank you for your response.

> [@nitzan.mazor](#):
>
> Where should I write it exactly and when should it be called?

You’ll need to go to your _Auth0 Dashboard \> Auth Pipeline \> Rules \> Create empty rule_ and insert that code snippet and save your changes. Then, you’ll be able to insert logic to support users only in a certain location. Note that Rules are executed post login.

> [@nitzan.mazor](#):
>
> My second request is that other than restrict users by their geo location, I would like to restrict them by country prefix also.

In this case, you’ll need to check for the users’ phone number prefix and determine if it begins with `+1` to grant them access.

```auto
function (user, context, callback) {
  if (user.phone_number[1] !== "1") {
    return callback(new UnauthorizedError('Access to this application has been temporarily revoked'));
  }
  
  callback(null, user, context);
}

```

However, be mindful that other country codes also begin with `+1`, such as Canada. It should not be an issue if you expect your users to log in with only US phone numbers, but it’s worth noting.

Please let me know how this works for you.

Thank you.

---

<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:** [January 4, 2022, 4:28pm UTC](https://community.auth0.com/t/show-error-if-chose-unsupported-location-prefix-of-unsupported-country/74957/6 "2022-01-04T16:28:59Z")

</div>

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