Automatic refresh token in react native app

Viewed 288

I am using Google calendar API in my react native app and every time refresh token expires after a time.so how can I manage to update token in app.

1 Answers

create a function that fetches data from your API provider. then in that function wrap your request in a try-catch block. and if the token is invalid then it goes to catch block. in the catch block, you can check the status of your request. your API provider has a particular status code for unauthorized requests. check if it is equal to the status of your request, then update your token and recursively call your function again.

Related