AccessTokenProvider component simplifies authentication by managing JWT tokens for all child components. You provide it with a function that fetches tokens from your backend, and it handles:
- Fetching the initial JWT token
- Automatically refreshing expired tokens
- Distributing tokens to all child components
See also Client-side authentication for more information on how to authenticate with Propel.
- With AccessTokenProvider
- Without AccessTokenProvider
Wrap your app with the
AccessTokenProvider and pass it the fetchToken function. This will ensure that all child components automatically receive the JWT token:Preferably the
fetchToken function lives outside of the component scope, in case you need to create it within the component scope please wrap it in a useCallback to prevent unnecessary re-renders:
AccessTokenProvider. The provided access token will be served to all of its child components:
You can use multiple
AccessTokenProvider components in your app, each with its own fetchToken function or accessToken prop. However, avoid nesting them to prevent unexpected behavior.