How do I update user metadata in signup flow?

  • We are using passwordless (email) authentication
  • We are passing language as query string (ui_locales=fr-CA) to login url
    • This can render the login page in french language
    • However the email verification is still sent to english language
    • We tried to set the user meta data in post sign up action (onExecutePostUserRegistration.js · GitHub)
      • However it error out with message that user doesn’t exist
    • We found an article where we can use ‘request_language’ to set the email language.
      • How do we pass ‘x-request-language’ to var lock = new Auth0LockPasswordless() in our login page?

Hi @dnationalwala,

To update the user_metadata in the signup flow, please use a Pre-User Registration Action.

For example:

/**
 * @param {Event} event - Details about registration event.
 * @param {PreUserRegistrationAPI} api
 */
exports.onExecutePreUserRegistration = async (event, api) => {
  api.user.setUserMetadata("locale", "fr-CA");  
};

(Reference: Pre User Registration Flow)

Then to set your preferred language in the email template, please refer to this solution here.

Please let me know if you have any questions.

Thanks,
Rueben

Hi Rueben,

Thank you for your reply.

exports.onExecutePreUserRegistration = async (event, api) => {
  api.user.setUserMetadata("locale", "fr-CA"); 
};

This could not update metadata for user that is created with passwordless email.

Is there alternative for passwordless authentication?

Hi @dnationalwala,

Thanks for the reply.

With Passwordless email, we will need to use a Post-Login Action script to check for the user’s first login attempt. Let me add that whenever a user signs up they are automatically logged in. Leveraging this, we can set the user metadata on their first login attempt.

For example:

exports.onExecutePostLogin = async (event, api) => {
  if(event.stats.logins_count === 1){
    api.user.setUserMetadata("locale", "fr-CA"); 
  }
};

Thanks,
Rueben

Hi Rueben,
Thank you for your reply.
Post login event is triggered after the email is sent in English language.

Hi @dnationalwala,

Thanks for the reply.

There are dependencies happening with your current flow that is limiting how the language can be set in the user_metadata. Specifically, this is a synchronous flow where the passwordless user must first sign up, before you can update the user_metadata. Because of this, there isn’t any way to prevent sending the verification email in English.

However, you could work around this by creating the user on their behalf and setting the user_metadata using the Management API Create a user endpoint.

This way, after the user is created, the correct user_metadata value is set, and the verification email template can set the correct language accordingly and send it to the user.