From 12fd3f147039c677838d9eea8a0c184985ba4902 Mon Sep 17 00:00:00 2001 From: Ansh Nanda Date: Wed, 27 Dec 2023 22:37:23 +0530 Subject: [PATCH] don't log user out when network isnt connected --- src/state/session/index.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx index aa8c94ebcd..8ec747c2bf 100644 --- a/src/state/session/index.tsx +++ b/src/state/session/index.tsx @@ -12,6 +12,8 @@ import {emitSessionDropped} from '../events' import {useLoggedOutViewControls} from '#/state/shell/logged-out' import {useCloseAllActiveElements} from '#/state/util' import {track} from '#/lib/analytics/analytics' +import {fetch as fetchNetworkState} from '@react-native-community/netinfo' +import * as Toast from 'view/com/util/Toast' let __globalAgent: BskyAgent = PUBLIC_BSKY_AGENT @@ -141,6 +143,9 @@ function createPersistSessionHandler( * to persist this data and wipe their tokens, effectively logging them * out. */ + // if creation failed, but it is a network error, we want to persist the + // data so that the user can try again + persistSessionCallback({ expired, refreshedAccount, @@ -444,6 +449,12 @@ export function Provider({children}: React.PropsWithChildren<{}>) { async account => { try { if (account) { + const currentNetworkState = await fetchNetworkState() + if (!currentNetworkState.isConnected) { + logger.info(`session: no internet connection, cannot reuse session`) + Toast.show('No internet connection. Please try again.') + return + } await initSession(account) } } catch (e) {