mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +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,
|
||||
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) {
|
||||
|
@ -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;
|
||||
|
@ -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 = {};
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user