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
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 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);
}
let me know if that is what you are looking to do.
Hi @kimcodes! Could you please provide a sample code snippet for the auto-populate an additionalsignupfield in Lock
part? ty!
@oleg were you able to get a code snippet to help you with your issue or did you still need that - if so I can take a look !
Hey there!
As this topic is related to Rules - Hooks - Actions and Rules & Hooks are being deprecated soon I’m excited to let you know about our next Ask me Anything session in the Forum on Thursday, January 18 with the Rules, Hooks and Actions team on Rules & Hooks and why Actions matter! Submit your questions in the thread above and our esteemed product experts will provide written answers on January 18. Find out more about Rules & Hooks and why Actions matter! Can’t wait to see you there!