Catch 401 and redirect

Hello,
I was wondering if anyone knows a way to catch a 401 api response (globally) and redirect back to the login page.

I am looking at the React Native course source code and in my backend I have an access token that expires.
Once it expires, the API calls return 401. At that point how can I detect it and redirect to the login page?
If there is not a global way I would have to check if (response.status === 401) after every call…

Thanks

1 Like