FormidableLabs / FormidableLabs/react-native-app-auth
Detect network errors on refresh token
- Dominant language
- Java
- Stars
- 2.3k
- Forks
- 473
- PR merge metrics
- No merged PRs in 30d
Description
Hi,
It appears that there's no robust way to check if the refresh request failed due to network errors. This is quite unfortunate, as it means you get logged out if you have no internet, which doesn't provide a great user experience. The only workaround I've found is to explicitly check if the error message contains "Connection error" for iOS and "Network error" for Android, but this feels far from ideal. Perhaps it would be possible to add another error code named "network_error" or something similar? Here's some code for reference:
``` javascript
try {
await refreshToken();
setIsLoggedIn(true);
} catch (error) {
if (message.includes('Connection error') || message.includes('Network error')) {
console.log('Connection error');
} else {
console.log('Refresh token failed, logging out...');
setSessionExpired(true);
setIsLoggedIn(false);
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.