Skip to content

feat: Add optional Accept-Language header configuration #1148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

subhankarmaiti
Copy link
Contributor

@subhankarmaiti subhankarmaiti commented Apr 23, 2025

Changes

This change introduces an optional configuration setting, acceptLanguage, allowing developers to specify preferred language tags (e.g., "en-US", "fr-CA,fr;q=0.9") during SDK initialization. When provided, the SDK will automatically include the Accept-Language HTTP header with the specified value in all outgoing API requests.

  • Usage Summary:
    Developers can now optionally provide an acceptLanguage string when initializing the SDK either via the Auth0 class constructor or the Auth0Provider component prop.

    // Using Auth0 class
    const auth0 = new Auth0({
      domain: 'YOUR_AUTH0_DOMAIN',
      clientId: 'YOUR_AUTH0_CLIENT_ID',
      acceptLanguage: 'es-ES,es;q=0.9' // Example value
    });
    
    // Using Auth0Provider
    <Auth0Provider
      domain="YOUR_AUTH0_DOMAIN"
      clientId="YOUR_AUTH0_CLIENT_ID"
      acceptLanguage="de-DE" // Example value
    >
      <App />
    </Auth0Provider>

    If provided, the Accept-Language header will be automatically included in subsequent API calls made by the SDK. This feature is optional and backward compatible; existing initializations without acceptLanguage will continue to function as before. An example has been added to EXAMPLES.md.

Testing

  • This change adds unit test coverage.
    • Unit tests were added in src/networking/__tests__/index.spec.js to verify the Client class behavior:
      • Ensures the Accept-Language header is not added when the acceptLanguage option is omitted during initialization.
      • Ensures the Accept-Language header is added with the correct value for GET, POST, and PATCH requests when the acceptLanguage option is provided.
      • Ensures the acceptLanguage option is correctly stored during client initialization.

Checklist

@subhankarmaiti subhankarmaiti requested a review from a team as a code owner April 23, 2025 13:26
@subhankarmaiti subhankarmaiti changed the title Sdk 5877 allow accept language feat: Add optional Accept-Language header configuration Apr 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant