Is there any way to get user's language in auth0 rules?

266 views Asked by At

I want to create a rule in auth0 that will add user’s language to user’s id token. So is there any way to achieve that? I can get country code and some other info from geoip but I can’t get language anywhere

1

There are 1 answers

0
snowpotatoe On

If you don't already have the langauge you could collect the user's language during the signup process by using the additionalsignupfields option in Lock to show a drop-down of languages. The user would then select an option during sign up and the selected value can be persisted in user_metadata.

Alternatively, you can customize your login page using JavaScript to detect the user's browser language, then auto-populate an additionalsignupfield in Lock with the value. We could even make this a hidden field if necessary.

Once stored in user_metadata we can then add that to the id_token something like:

function(user, context, callback) {

  // copy user metadata value in id token
  context.idToken['http://examplesite/user_lang'] = user.user_metadata.user_lang;

  callback(null, user, context);
}