Manage authentication across components.
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:
AccessTokenProvider
and pass it the fetchToken
function. This will ensure that all child components automatically receive the JWT token: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:
AccessTokenProvider
components in your app, each with its own fetchToken
function or accessToken
prop. However, avoid nesting them to prevent unexpected behavior.