Skip to content

Commit

Permalink
fallback to login screen when connection not allowed
Browse files Browse the repository at this point in the history
  • Loading branch information
rolandosborne committed Jun 28, 2023
1 parent 4b52c47 commit f42fabf
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
6 changes: 5 additions & 1 deletion app/mobile/src/context/useAppContext.hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function useAppContext() {
session: null,
status: null,
loggingOut: false,
loggedOut: false,
adminToken: null,
version: getVersion(),
});
Expand Down Expand Up @@ -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 };
Expand All @@ -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);
Expand All @@ -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 };
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 1 addition & 3 deletions app/mobile/src/context/useProfileContext.hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export function useProfileContext() {
identity: {},
server: null,
imageUrl: null,
loggedOut: false,
});
const store = useContext(StoreContext);

Expand Down Expand Up @@ -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;
Expand Down
5 changes: 5 additions & 0 deletions app/mobile/src/session/profileIcon/useProfileIcon.hook.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { useState, useEffect, useContext } from 'react';
import { AppContext } from 'context/AppContext';
import { useNavigate } from 'react-router-dom';

export function useProfileIcon() {

const [state, setState] = useState({
disconnected: false,
});

const navigate = useNavigate();
const app = useContext(AppContext);

const updateState = (value) => {
Expand All @@ -16,6 +18,9 @@ export function useProfileIcon() {
useEffect(() => {
const { status } = app.state
updateState({ disconnected: status === 'disconnected' });
if (app.state.loggedOut) {
navigate("/");
}
}, [app]);

const actions = {};
Expand Down
8 changes: 0 additions & 8 deletions app/mobile/src/session/useSession.hook.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit f42fabf

Please sign in to comment.