Appearance
Handling network disconnection
Managing authentication retries after network disconnect
If your user's devices get disconnected, any calls to fetch the user's current state or their access token via getAccessToken()
will fail while the network is disconnected. We recommend using the NetInfo package in order to optimistically query for the access token when the network is reconnected.
Below is an example code snippet:
tsx
import {usePrivy} from '@privy-io/expo';
import {useNetInfo} from '@react-native-community/netinfo';
...
// mount useNetInfo hook in the application upon page load
const { getAccessToken } = usePrivy();
const { isConnected } = useNetInfo();
useEffect(() => {
const refreshUserOnReconnect = async () => {
if (isConnected) {
// Get the access token
const accessToken = await getAccessToken();
...
// Add additional logic for re-initializing your application
}
refreshUserOnReconnect();
}
}, [isConnected])