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 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.
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.
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.
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.
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.