Reputation: 3776
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
Upvotes: 0
Views: 308
Reputation: 767
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);
}
Upvotes: 1