FormidableLabs / FormidableLabs/react-native-app-auth

Detect network errors on refresh token

Aperta
#861 1 commento 0 reazioni 1 assegnatario Rivendicata da @faizplus Vedi su GitHub
enhancement issue-accepted
Lingua principale
Java
Stelle
2.3k
Fork
473
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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);
}
}
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.