Skip to content

feat: Add optional Accept-Language header configuration #1148

Closed
subhankarmaiti wants to merge 3 commits into
masterfrom
SDK-5877-allow-accept-language
Closed

feat: Add optional Accept-Language header configuration #1148
subhankarmaiti wants to merge 3 commits into
masterfrom
SDK-5877-allow-accept-language

Conversation

@subhankarmaiti
Copy link
Copy Markdown
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
@subhankarmaiti
Copy link
Copy Markdown
Contributor Author

closing as #1155 is going to solve the same issue

@subhankarmaiti subhankarmaiti deleted the SDK-5877-allow-accept-language branch April 29, 2025 10:01
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