Auth0 Home Blog Docs

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


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


:wave: saw your question on SO Ill share it here in case others are looking for a way.

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 theid_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);

let me know if that is what you are looking to do.