I’m using the @auth0/react project for a static single-page-app that relies on an API hosted by my team. (This project isn’t part of our main application, but requires some data from the main application which is fetched via REST API.)
The API will authenticate requests from the SPA using a JWT access token, and I’ve figured out how to get the access token for the API from Auth0 using
getAccessTokenSilently. I’ve also learned how to attach metadata as a custom claim to that access token.
What I DON’T know is how to get a refreshed access token immediately after the user signs in. As far as I know, I need to initialize the Auth0 context in react, wait for the session to load, and then I can make a request for the access token. This means that I’m waiting at least 100ms before I can even start requesting data from my API, which is unacceptable for the initial render. Is there some kind of Rule or something I can configure in Auth0 so that a valid access token is included in the idToken (or otherwise) so I can cut this round trip out of my initial render?
Obviously I can cache the access token for a short time, but that doesn’t help the all-important initial render time.