Parallel api calls with Authorization in react native

Viewed 119

Given the fact that, to make every successful API calls, we need auth token. In a screen Three API calls are being made parallel. Even before making first API call, the auth token was expired. How do you ensure, just one call is made and you know token is expired and new token is received from backend and before further API calls are made.

Any idea on how to do this???

1 Answers

If i really understand what you are looking for, request should have always a token in the bearer. but you have to refresh it before getting expired.

For example , if you are using keycloak, for the first connection , you must have an access token & a refresh token.

If we suppose that the lifetime of access token is 5 minutes , you have to refresh the access token with the refresh token before 5 minutes past. (like at 4,30 minutes with a setInterval for example as show in the workflow above).

enter image description here

Related