about summary refs log tree commit diff
path: root/src/lib/hooks/useAccountSwitcher.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/hooks/useAccountSwitcher.ts')
-rw-r--r--src/lib/hooks/useAccountSwitcher.ts23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/lib/hooks/useAccountSwitcher.ts b/src/lib/hooks/useAccountSwitcher.ts
index 82f4565e9..3851fe601 100644
--- a/src/lib/hooks/useAccountSwitcher.ts
+++ b/src/lib/hooks/useAccountSwitcher.ts
@@ -7,22 +7,34 @@ import {useAnalytics} from '#/lib/analytics/analytics'
 import {useSessionApi, SessionAccount} from '#/state/session'
 import * as Toast from '#/view/com/util/Toast'
 import {useCloseAllActiveElements} from '#/state/util'
+import {useLoggedOutViewControls} from '#/state/shell/logged-out'
 
 export function useAccountSwitcher() {
   const {track} = useAnalytics()
   const {selectAccount, clearCurrentAccount} = useSessionApi()
   const closeAllActiveElements = useCloseAllActiveElements()
   const navigation = useNavigation<NavigationProp>()
+  const {setShowLoggedOut} = useLoggedOutViewControls()
 
   const onPressSwitchAccount = useCallback(
-    async (acct: SessionAccount) => {
+    async (account: SessionAccount) => {
       track('Settings:SwitchAccountButtonClicked')
 
       try {
-        closeAllActiveElements()
-        navigation.navigate(isWeb ? 'Home' : 'HomeTab')
-        await selectAccount(acct)
-        Toast.show(`Signed in as ${acct.handle}`)
+        if (account.accessJwt) {
+          closeAllActiveElements()
+          navigation.navigate(isWeb ? 'Home' : 'HomeTab')
+          await selectAccount(account)
+          setTimeout(() => {
+            Toast.show(`Signed in as @${account.handle}`)
+          }, 100)
+        } else {
+          setShowLoggedOut(true)
+          Toast.show(
+            `Please sign in as @${account.handle}`,
+            'circle-exclamation',
+          )
+        }
       } catch (e) {
         Toast.show('Sorry! We need you to enter your password.')
         clearCurrentAccount() // back user out to login
@@ -34,6 +46,7 @@ export function useAccountSwitcher() {
       selectAccount,
       closeAllActiveElements,
       navigation,
+      setShowLoggedOut,
     ],
   )