|
1 | 1 | # Examples using react-native-auth0 |
2 | 2 |
|
| 3 | +- [SDK Configuration](#sdk-configuration) |
| 4 | + - [Setting the Accept-Language Header](#setting-the-accept-language-header) |
3 | 5 | - [Authentication API](#authentication-api) |
4 | 6 | - [Login with Password Realm Grant](#login-with-password-realm-grant) |
5 | 7 | - [Get user information using user's access_token](#get-user-information-using-users-access_token) |
|
21 | 23 | - [iOS](#ios) |
22 | 24 | - [Expo](#expo) |
23 | 25 |
|
| 26 | +## SDK Configuration |
| 27 | + |
| 28 | +This section covers examples related to configuring the behavior of the Auth0 SDK itself. |
| 29 | + |
| 30 | +### Setting the Accept-Language Header |
| 31 | + |
| 32 | +You can configure the SDK to automatically send the `Accept-Language` HTTP header with all outgoing requests. This is useful if you want to signal your preferred language(s) to Auth0, which might influence the language used in error messages or other localized content returned by Auth0 APIs. |
| 33 | + |
| 34 | + |
| 35 | +Provide the `acceptLanguage` option during initialization. The value should be a string conforming to the standard `Accept-Language` header format (e.g., `en-US`, `fr-CA,fr;q=0.9`). |
| 36 | + |
| 37 | +**Using the `Auth0` class:** |
| 38 | + |
| 39 | +```js |
| 40 | +import Auth0 from 'react-native-auth0'; |
| 41 | + |
| 42 | +const auth0 = new Auth0({ |
| 43 | + domain: 'YOUR_AUTH0_DOMAIN', |
| 44 | + clientId: 'YOUR_AUTH0_CLIENT_ID', |
| 45 | + // Set preferred language(s) |
| 46 | + acceptLanguage: 'es-ES,es;q=0.9' |
| 47 | +}); |
| 48 | + |
| 49 | +// All subsequent API calls made using this auth0 instance |
| 50 | +// (e.g., auth0.auth.passwordlessWithSMS()) |
| 51 | +// will include the 'Accept-Language: es-ES,es;q=0.9' header. |
| 52 | +``` |
| 53 | + |
| 54 | +**Using the Auth0Provider hook:** |
| 55 | + |
| 56 | +```js |
| 57 | +import { Auth0Provider } from 'react-native-auth0'; |
| 58 | + |
| 59 | +const App = () => { |
| 60 | + return ( |
| 61 | + <Auth0Provider |
| 62 | + domain="YOUR_AUTH0_DOMAIN" |
| 63 | + clientId="YOUR_AUTH0_CLIENT_ID" |
| 64 | + // Set preferred language(s) |
| 65 | + acceptLanguage="de-DE" |
| 66 | + > |
| 67 | + {/* YOUR APP */} |
| 68 | + </Auth0Provider> |
| 69 | + ); |
| 70 | +}; |
| 71 | + |
| 72 | +export default App; |
| 73 | + |
| 74 | +// All subsequent API calls made via the useAuth0() hook derived |
| 75 | +// from this provider will include the 'Accept-Language: de-DE' header. |
| 76 | + |
| 77 | +``` |
| 78 | + |
24 | 79 | ## Authentication API |
25 | 80 |
|
26 | 81 | Unlike web authentication, we do not provide a hook for integrating with the Authentication API. |
|
0 commit comments