I was able to set up a rule that grabs the ui_locales and sets it as the user_metadat.lang, but at this point in the pipeline the email template has already used the older user_metadata object with no language, so it won’t affect any emails going out on the first login cycle.
Are you users database users? Or do you have social/enterprise users as well?
I am going to post the rule as it could help for other emails (like password reset).
function(user, context, callback){
// set metadata object
user.user_metadata = user.user_metadata || {};
// if lang exists for the user, skip rule
if(user.user_metadata.lang){
callback(null, user, context);
}
// set language variable to ui_locales or default to 'en'
let preferedLanguage = context.request.query.ui_locales || 'en';
// update the user_metadata that will be part of the response
user.user_metadata.lang = preferedLanguage;
// persist the user_metadata update
auth0.users.updateUserMetadata(user.user_id, user.user_metadata)
.then(function(){
callback(null, user, context);
})
.catch(function(err){
callback(err);
});
}