From f42fabf08d8fb933fc9fd27632249797031f7b0a Mon Sep 17 00:00:00 2001 From: balzack Date: Tue, 27 Jun 2023 22:56:05 -0700 Subject: [PATCH] fallback to login screen when connection not allowed --- app/mobile/src/context/useAppContext.hook.js | 6 +++++- app/mobile/src/context/useProfileContext.hook.js | 4 +--- app/mobile/src/session/profileIcon/useProfileIcon.hook.js | 5 +++++ app/mobile/src/session/useSession.hook.js | 8 -------- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/app/mobile/src/context/useAppContext.hook.js b/app/mobile/src/context/useAppContext.hook.js index c1a54202..19864cb8 100644 --- a/app/mobile/src/context/useAppContext.hook.js +++ b/app/mobile/src/context/useAppContext.hook.js @@ -21,6 +21,7 @@ export function useAppContext() { session: null, status: null, loggingOut: false, + loggedOut: false, adminToken: null, version: getVersion(), }); @@ -110,6 +111,7 @@ export function useAppContext() { if (!init.current || access.current) { throw new Error('invalid session state'); } + updateState({ loggedOut: false }); await addAccount(server, username, password, token); const session = await setLogin(username, server, password, getApplicationName(), getVersion(), getDeviceId(), deviceToken.current, pushType.current, notifications) access.current = { server, token: session.appToken, guid: session.guid }; @@ -123,6 +125,7 @@ export function useAppContext() { if (!init.current || access.current) { throw new Error('invalid session state'); } + updateState({ loggedOut: false }); const session = await setAccountAccess(server, token, getApplicationName(), getVersion(), getDeviceId(), deviceToken.current, pushType.current, notifications); access.current = { server, token: session.appToken, guid: session.guid }; await store.actions.setSession(access.current); @@ -135,6 +138,7 @@ export function useAppContext() { if (!init.current || access.current) { throw new Error('invalid session state'); } + updateState({ loggedOut: false }); const acc = username.split('@'); const session = await setLogin(acc[0], acc[1], password, getApplicationName(), getVersion(), getDeviceId(), deviceToken.current, pushType.current, notifications) access.current = { server: acc[1], token: session.appToken, guid: session.guid }; @@ -164,7 +168,7 @@ export function useAppContext() { access.current = null; await store.actions.clearSession(); await store.actions.clearFirstRun(); - updateState({ loggingOut: false }); + updateState({ loggedOut: true, loggingOut: false }); }, remove: async () => { if (!access.current) { diff --git a/app/mobile/src/context/useProfileContext.hook.js b/app/mobile/src/context/useProfileContext.hook.js index 90b5ff62..42f564d0 100644 --- a/app/mobile/src/context/useProfileContext.hook.js +++ b/app/mobile/src/context/useProfileContext.hook.js @@ -12,7 +12,6 @@ export function useProfileContext() { identity: {}, server: null, imageUrl: null, - loggedOut: false, }); const store = useContext(StoreContext); @@ -57,14 +56,13 @@ export function useProfileContext() { const identity = await store.actions.getProfile(guid); const revision = await store.actions.getProfileRevision(guid); const imageUrl = identity?.image ? getProfileImageUrl(server, token, revision) : null; - updateState({ loggedOut: false, offsync: false, identity, imageUrl, server }); + updateState({ offsync: false, identity, imageUrl, server }); setRevision.current = revision; curRevision.current = revision; access.current = session; }, clearSession: () => { access.current = null; - updateState({ loggedOut: true }); }, setRevision: (rev) => { curRevision.current = rev; diff --git a/app/mobile/src/session/profileIcon/useProfileIcon.hook.js b/app/mobile/src/session/profileIcon/useProfileIcon.hook.js index 081a3ea9..4b43796f 100644 --- a/app/mobile/src/session/profileIcon/useProfileIcon.hook.js +++ b/app/mobile/src/session/profileIcon/useProfileIcon.hook.js @@ -1,5 +1,6 @@ import { useState, useEffect, useContext } from 'react'; import { AppContext } from 'context/AppContext'; +import { useNavigate } from 'react-router-dom'; export function useProfileIcon() { @@ -7,6 +8,7 @@ export function useProfileIcon() { disconnected: false, }); + const navigate = useNavigate(); const app = useContext(AppContext); const updateState = (value) => { @@ -16,6 +18,9 @@ export function useProfileIcon() { useEffect(() => { const { status } = app.state updateState({ disconnected: status === 'disconnected' }); + if (app.state.loggedOut) { + navigate("/"); + } }, [app]); const actions = {}; diff --git a/app/mobile/src/session/useSession.hook.js b/app/mobile/src/session/useSession.hook.js index 64c3e2be..b0013d4c 100644 --- a/app/mobile/src/session/useSession.hook.js +++ b/app/mobile/src/session/useSession.hook.js @@ -1,6 +1,5 @@ import { useRef, useState, useEffect, useContext } from 'react'; import { useWindowDimensions } from 'react-native'; -import { useNavigate } from 'react-router-dom'; import config from 'constants/Config'; import { StoreContext } from 'context/StoreContext'; import { CardContext } from 'context/CardContext'; @@ -34,19 +33,12 @@ export function useSession() { const profile = useContext(ProfileContext); const store = useContext(StoreContext); const dimensions = useWindowDimensions(); - const navigate = useNavigate(); const tabbed = useRef(null); const updateState = (value) => { setState((s) => ({ ...s, ...value })); } - useEffect(() => { - if (profile.state.loggedOut) { - navigate("/"); - } - }, [profile.state]); - useEffect(() => { const ringing = []; const expired = Date.now();