detecting logged out state in mobile app

This commit is contained in:
balzack 2023-06-27 18:40:50 -07:00
parent fabad03bab
commit 766bc52965
4 changed files with 18 additions and 6 deletions

View File

@ -350,6 +350,8 @@ PODS:
- ReactCommon/turbomodule/core - ReactCommon/turbomodule/core
- react-native-sqlite-storage (6.0.1): - react-native-sqlite-storage (6.0.1):
- React-Core - React-Core
- react-native-unifiedpush-connector (0.1.5):
- React-Core
- react-native-video (5.2.1): - react-native-video (5.2.1):
- React-Core - React-Core
- react-native-video/Video (= 5.2.1) - react-native-video/Video (= 5.2.1)
@ -549,6 +551,7 @@ DEPENDENCIES:
- react-native-rsa-native (from `../node_modules/react-native-rsa-native`) - react-native-rsa-native (from `../node_modules/react-native-rsa-native`)
- react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`) - react-native-safe-area-context (from `../node_modules/react-native-safe-area-context`)
- react-native-sqlite-storage (from `../node_modules/react-native-sqlite-storage`) - react-native-sqlite-storage (from `../node_modules/react-native-sqlite-storage`)
- react-native-unifiedpush-connector (from `../node_modules/react-native-unifiedpush-connector`)
- react-native-video (from `../node_modules/react-native-video`) - react-native-video (from `../node_modules/react-native-video`)
- react-native-webrtc (from `../node_modules/react-native-webrtc`) - react-native-webrtc (from `../node_modules/react-native-webrtc`)
- React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`) - React-perflogger (from `../node_modules/react-native/ReactCommon/reactperflogger`)
@ -657,6 +660,8 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-safe-area-context" :path: "../node_modules/react-native-safe-area-context"
react-native-sqlite-storage: react-native-sqlite-storage:
:path: "../node_modules/react-native-sqlite-storage" :path: "../node_modules/react-native-sqlite-storage"
react-native-unifiedpush-connector:
:path: "../node_modules/react-native-unifiedpush-connector"
react-native-video: react-native-video:
:path: "../node_modules/react-native-video" :path: "../node_modules/react-native-video"
react-native-webrtc: react-native-webrtc:
@ -761,6 +766,7 @@ SPEC CHECKSUMS:
react-native-rsa-native: 12132eb627797529fdb1f0d22fd0f8f9678df64a react-native-rsa-native: 12132eb627797529fdb1f0d22fd0f8f9678df64a
react-native-safe-area-context: 39c2d8be3328df5d437ac1700f4f3a4f75716acc react-native-safe-area-context: 39c2d8be3328df5d437ac1700f4f3a4f75716acc
react-native-sqlite-storage: f6d515e1c446d1e6d026aa5352908a25d4de3261 react-native-sqlite-storage: f6d515e1c446d1e6d026aa5352908a25d4de3261
react-native-unifiedpush-connector: 4a2617507562f177726203bda5dea0a00855ac2b
react-native-video: c26780b224543c62d5e1b2a7244a5cd1b50e8253 react-native-video: c26780b224543c62d5e1b2a7244a5cd1b50e8253
react-native-webrtc: 0df36747802476e758af6b6dceccdeaed8c826c2 react-native-webrtc: 0df36747802476e758af6b6dceccdeaed8c826c2
React-perflogger: af8a3d31546077f42d729b949925cc4549f14def React-perflogger: af8a3d31546077f42d729b949925cc4549f14def

View File

@ -1,5 +1,4 @@
import { useEffect, useState, useRef, useContext } from 'react'; import { useEffect, useState, useRef, useContext } from 'react';
import { useNavigate } from 'react-router-dom';
import { Alert } from 'react-native'; import { Alert } from 'react-native';
import { setLogin } from 'api/setLogin'; import { setLogin } from 'api/setLogin';
import { clearLogin } from 'api/clearLogin'; import { clearLogin } from 'api/clearLogin';
@ -26,8 +25,6 @@ export function useAppContext() {
version: getVersion(), version: getVersion(),
}); });
const navigate = useNavigate();
const store = useContext(StoreContext); const store = useContext(StoreContext);
const account = useContext(AccountContext); const account = useContext(AccountContext);
const profile = useContext(ProfileContext); const profile = useContext(ProfileContext);
@ -168,7 +165,6 @@ export function useAppContext() {
await store.actions.clearSession(); await store.actions.clearSession();
await store.actions.clearFirstRun(); await store.actions.clearFirstRun();
updateState({ loggingOut: false }); updateState({ loggingOut: false });
navigate('/');
}, },
remove: async () => { remove: async () => {
if (!access.current) { if (!access.current) {
@ -218,7 +214,9 @@ export function useAppContext() {
} }
} }
ws.current.onopen = () => { ws.current.onopen = () => {
ws.current.send(JSON.stringify({ AppToken: session.token })) if (ws.current) {
ws.current.send(JSON.stringify({ AppToken: session.token }))
}
} }
ws.current.onclose = (e) => { ws.current.onclose = (e) => {
console.log(e) console.log(e)

View File

@ -12,6 +12,7 @@ export function useProfileContext() {
identity: {}, identity: {},
server: null, server: null,
imageUrl: null, imageUrl: null,
loggedOut: false,
}); });
const store = useContext(StoreContext); const store = useContext(StoreContext);
@ -56,13 +57,14 @@ export function useProfileContext() {
const identity = await store.actions.getProfile(guid); const identity = await store.actions.getProfile(guid);
const revision = await store.actions.getProfileRevision(guid); const revision = await store.actions.getProfileRevision(guid);
const imageUrl = identity?.image ? getProfileImageUrl(server, token, revision) : null; const imageUrl = identity?.image ? getProfileImageUrl(server, token, revision) : null;
updateState({ offsync: false, identity, imageUrl, server }); updateState({ loggedOut: false, offsync: false, identity, imageUrl, server });
setRevision.current = revision; setRevision.current = revision;
curRevision.current = revision; curRevision.current = revision;
access.current = session; access.current = session;
}, },
clearSession: () => { clearSession: () => {
access.current = null; access.current = null;
updateState({ loggedOut: true });
}, },
setRevision: (rev) => { setRevision: (rev) => {
curRevision.current = rev; curRevision.current = rev;

View File

@ -41,6 +41,12 @@ export function useSession() {
setState((s) => ({ ...s, ...value })); setState((s) => ({ ...s, ...value }));
} }
useEffect(() => {
if (profile.state.loggedOut) {
navigate("/");
}
}, [profile.state]);
useEffect(() => { useEffect(() => {
const ringing = []; const ringing = [];
const expired = Date.now(); const expired = Date.now();