No context.renderLanguage or context.request.language in Pre User Registration hook after /passwordless/start

I wrote a Pre User Registration hook to add the user locale/language to the user meta data in order to send out a localized mail with the verification code , but I could not retrieve a value from context.renderLanguage nor from context.request.language within this hook after triggering the API call /passwordless/start despite I also added an authParams parameter with ui_locales: de inside - here is my hook code:

module.exports = function (user, context, cb) {
  var response = {};
  user.user_metadata = user.user_metadata || {};
  user.user_metadata.emailVerificationSentDate = new Date().valueOf();
  console.log(`Set emailVerificationSentDate to ${user.user_metadata.emailVerificationSentDate}`);
  user.user_metadata.lang = context.renderLanguage || context.request.language || 'en';
  console.log(`Set lang to ${user.user_metadata.lang}`);
  response.user = user;
  cb(null, response);
};

If I am using the normal Auth0 dialog for signup, a value for context.renderLanguage is available. But how can I transfer the user locale using passwordless signup by directly calling the API (not using any Auth0 UI). In fact I do not really wanted to directly use the Auth0 API, but have tried to use GitHub - auth0/react-native-auth0: React Native toolkit for Auth0 API.

Hi @norbert.schuler,

Welcome to the Community!

I’m looking into this now, and will let you know what I find.

Thanks,

Stephanie

1 Like

Thank you for investigating this. I just recognized I do not know if it even makes sense to try to store the language in the user metadata in a Pre User Registration hook as the user account maybe does not exists at that time. I want to store it in order to localize the email for the one-time password authentication of a user like this:

Is there another way to retrieve the user’s language for this and other mail templates?

We will use the solution described at https://auth0.com/docs/connections/passwordless/guides/email-otp for now taking the locale from the request_language directly in the email template with e.g. {% if request_language contains 'de' %}. That’s at least better then no localization.

2 Likes

I’m glad you found a solution! Yes, when /passwordless/start is called with the x-request-language specified in the request header, the passed language will be available. Otherwise, the user’s browser language will be used for the request_language variable.

1 Like

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.