Handling Multiple Locales

Hello everyone. I’m new to Auth0 and I need help about something. Let’s say I have 4 locales in my website. Should I handle them with 4 client id and domain or is there a way to handle it more easily? Because if I use different client id and domain for each I will need to handle them in auth0 client and also the callback functions after successful login.
Thanks in advance

Hi @serhat.keles7,

Welcome to the Auth0 Community!

The Auth0 Universal Login experience is localized to multiple languages. Please see here for more: Universal Login Internationalization

If the scope of this question is limited to the Auth0 aspect of your app, you shouldn’t need to create four different clientIDs and handle switching them.

Please let me know if I am misunderstanding or if you have any additional questions!

Best,

Mary Beth

Thank you for the response. My issue is more like different databases for different locales. I mean login from mydomain.com/en and mydomain.com/de should be stored in different databases. I thought maybe I can create auth0Client dynamically according to locale and set different clientId for each locale but if there is a simpler solution I’d like to hear.

Thanks

Hi @serhat.keles7,

You shouldn’t have to create a clientId for each locale. You could use an Action to check for the locale.

Using mydomain.com/en or mydomain.com/de, you can create an Action that looks like this:

exports.onExecutePostLogin = async (event, api) => {
  const locale = event.request.query.locale || event.user.app_metadata?.locale || 'en';  // Get the locale from query or metadata
  
  // Set user metadata based on locale
  if (locale === 'de') {
    event.user.app_metadata = event.user.app_metadata || {};
    event.user.app_metadata.localeDatabase = 'de_users_database';  // Store the database name for German users
  } else if (locale === 'fr') {
    event.user.app_metadata = event.user.app_metadata || {};
    event.user.app_metadata.localeDatabase = 'fr_users_database';  // Store the database name for French users
  } else {
    event.user.app_metadata = event.user.app_metadata || {};
    event.user.app_metadata.localeDatabase = 'en_users_database';  // Default to English users database
  }

  // Save app_metadata after modification
  api.user.setAppMetadata("localeDatabase", event.user.app_metadata.localeDatabase);

  // Optionally, you can also add a custom claim for the locale
  api.idToken.setCustomClaim("localeDatabase", event.user.app_metadata.localeDatabase);

  // Continue the flow
};

You can use the app_metadata.localeDatabase on your end however you wish.

Best,

Mary Beth

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