mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 20:49:16 +00:00
fallback to login screen when connection not allowed
This commit is contained in:
parent
4b52c477f8
commit
f42fabf08d
@ -21,6 +21,7 @@ export function useAppContext() {
|
|||||||
session: null,
|
session: null,
|
||||||
status: null,
|
status: null,
|
||||||
loggingOut: false,
|
loggingOut: false,
|
||||||
|
loggedOut: false,
|
||||||
adminToken: null,
|
adminToken: null,
|
||||||
version: getVersion(),
|
version: getVersion(),
|
||||||
});
|
});
|
||||||
@ -110,6 +111,7 @@ export function useAppContext() {
|
|||||||
if (!init.current || access.current) {
|
if (!init.current || access.current) {
|
||||||
throw new Error('invalid session state');
|
throw new Error('invalid session state');
|
||||||
}
|
}
|
||||||
|
updateState({ loggedOut: false });
|
||||||
await addAccount(server, username, password, token);
|
await addAccount(server, username, password, token);
|
||||||
const session = await setLogin(username, server, password, getApplicationName(), getVersion(), getDeviceId(), deviceToken.current, pushType.current, notifications)
|
const session = await setLogin(username, server, password, getApplicationName(), getVersion(), getDeviceId(), deviceToken.current, pushType.current, notifications)
|
||||||
access.current = { server, token: session.appToken, guid: session.guid };
|
access.current = { server, token: session.appToken, guid: session.guid };
|
||||||
@ -123,6 +125,7 @@ export function useAppContext() {
|
|||||||
if (!init.current || access.current) {
|
if (!init.current || access.current) {
|
||||||
throw new Error('invalid session state');
|
throw new Error('invalid session state');
|
||||||
}
|
}
|
||||||
|
updateState({ loggedOut: false });
|
||||||
const session = await setAccountAccess(server, token, getApplicationName(), getVersion(), getDeviceId(), deviceToken.current, pushType.current, notifications);
|
const session = await setAccountAccess(server, token, getApplicationName(), getVersion(), getDeviceId(), deviceToken.current, pushType.current, notifications);
|
||||||
access.current = { server, token: session.appToken, guid: session.guid };
|
access.current = { server, token: session.appToken, guid: session.guid };
|
||||||
await store.actions.setSession(access.current);
|
await store.actions.setSession(access.current);
|
||||||
@ -135,6 +138,7 @@ export function useAppContext() {
|
|||||||
if (!init.current || access.current) {
|
if (!init.current || access.current) {
|
||||||
throw new Error('invalid session state');
|
throw new Error('invalid session state');
|
||||||
}
|
}
|
||||||
|
updateState({ loggedOut: false });
|
||||||
const acc = username.split('@');
|
const acc = username.split('@');
|
||||||
const session = await setLogin(acc[0], acc[1], password, getApplicationName(), getVersion(), getDeviceId(), deviceToken.current, pushType.current, notifications)
|
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 };
|
access.current = { server: acc[1], token: session.appToken, guid: session.guid };
|
||||||
@ -164,7 +168,7 @@ export function useAppContext() {
|
|||||||
access.current = null;
|
access.current = null;
|
||||||
await store.actions.clearSession();
|
await store.actions.clearSession();
|
||||||
await store.actions.clearFirstRun();
|
await store.actions.clearFirstRun();
|
||||||
updateState({ loggingOut: false });
|
updateState({ loggedOut: true, loggingOut: false });
|
||||||
},
|
},
|
||||||
remove: async () => {
|
remove: async () => {
|
||||||
if (!access.current) {
|
if (!access.current) {
|
||||||
|
@ -12,7 +12,6 @@ export function useProfileContext() {
|
|||||||
identity: {},
|
identity: {},
|
||||||
server: null,
|
server: null,
|
||||||
imageUrl: null,
|
imageUrl: null,
|
||||||
loggedOut: false,
|
|
||||||
});
|
});
|
||||||
const store = useContext(StoreContext);
|
const store = useContext(StoreContext);
|
||||||
|
|
||||||
@ -57,14 +56,13 @@ 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({ loggedOut: false, offsync: false, identity, imageUrl, server });
|
updateState({ 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;
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { useState, useEffect, useContext } from 'react';
|
import { useState, useEffect, useContext } from 'react';
|
||||||
import { AppContext } from 'context/AppContext';
|
import { AppContext } from 'context/AppContext';
|
||||||
|
import { useNavigate } from 'react-router-dom';
|
||||||
|
|
||||||
export function useProfileIcon() {
|
export function useProfileIcon() {
|
||||||
|
|
||||||
@ -7,6 +8,7 @@ export function useProfileIcon() {
|
|||||||
disconnected: false,
|
disconnected: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const navigate = useNavigate();
|
||||||
const app = useContext(AppContext);
|
const app = useContext(AppContext);
|
||||||
|
|
||||||
const updateState = (value) => {
|
const updateState = (value) => {
|
||||||
@ -16,6 +18,9 @@ export function useProfileIcon() {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const { status } = app.state
|
const { status } = app.state
|
||||||
updateState({ disconnected: status === 'disconnected' });
|
updateState({ disconnected: status === 'disconnected' });
|
||||||
|
if (app.state.loggedOut) {
|
||||||
|
navigate("/");
|
||||||
|
}
|
||||||
}, [app]);
|
}, [app]);
|
||||||
|
|
||||||
const actions = {};
|
const actions = {};
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { useRef, useState, useEffect, useContext } from 'react';
|
import { useRef, useState, useEffect, useContext } from 'react';
|
||||||
import { useWindowDimensions } from 'react-native';
|
import { useWindowDimensions } from 'react-native';
|
||||||
import { useNavigate } from 'react-router-dom';
|
|
||||||
import config from 'constants/Config';
|
import config from 'constants/Config';
|
||||||
import { StoreContext } from 'context/StoreContext';
|
import { StoreContext } from 'context/StoreContext';
|
||||||
import { CardContext } from 'context/CardContext';
|
import { CardContext } from 'context/CardContext';
|
||||||
@ -34,19 +33,12 @@ export function useSession() {
|
|||||||
const profile = useContext(ProfileContext);
|
const profile = useContext(ProfileContext);
|
||||||
const store = useContext(StoreContext);
|
const store = useContext(StoreContext);
|
||||||
const dimensions = useWindowDimensions();
|
const dimensions = useWindowDimensions();
|
||||||
const navigate = useNavigate();
|
|
||||||
const tabbed = useRef(null);
|
const tabbed = useRef(null);
|
||||||
|
|
||||||
const updateState = (value) => {
|
const updateState = (value) => {
|
||||||
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();
|
||||||
|
Loading…
Reference in New Issue
Block a user