mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
detect logged out state and redirect
This commit is contained in:
parent
ce0c1ad75f
commit
ef0f1a2997
@ -1,4 +1,5 @@
|
|||||||
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';
|
||||||
@ -24,6 +25,9 @@ export function useAppContext() {
|
|||||||
adminToken: null,
|
adminToken: null,
|
||||||
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);
|
||||||
@ -164,6 +168,7 @@ 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) {
|
||||||
@ -179,6 +184,10 @@ export function useAppContext() {
|
|||||||
const setWebsocket = (session) => {
|
const setWebsocket = (session) => {
|
||||||
ws.current = createWebsocket(`wss://${session.server}/status?mode=ring`);
|
ws.current = createWebsocket(`wss://${session.server}/status?mode=ring`);
|
||||||
ws.current.onmessage = (ev) => {
|
ws.current.onmessage = (ev) => {
|
||||||
|
if (ev.data == '') {
|
||||||
|
actions.logout();
|
||||||
|
return;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
delay.current = 0;
|
delay.current = 0;
|
||||||
let activity = JSON.parse(ev.data);
|
let activity = JSON.parse(ev.data);
|
||||||
|
@ -128,7 +128,6 @@ export function useProfile() {
|
|||||||
const actions = {
|
const actions = {
|
||||||
logout: async () => {
|
logout: async () => {
|
||||||
await app.actions.logout();
|
await app.actions.logout();
|
||||||
navigate('/');
|
|
||||||
},
|
},
|
||||||
remove: async () => {
|
remove: async () => {
|
||||||
await app.actions.remove();
|
await app.actions.remove();
|
||||||
|
@ -57,6 +57,7 @@ func Status(w http.ResponseWriter, r *http.Request) {
|
|||||||
// retrieve reference account
|
// retrieve reference account
|
||||||
var session store.Session
|
var session store.Session
|
||||||
if err := store.DB.Preload("Account").Where("account_id = ? AND token = ?", target, access).First(&session).Error; err != nil {
|
if err := store.DB.Preload("Account").Where("account_id = ? AND token = ?", target, access).First(&session).Error; err != nil {
|
||||||
|
conn.WriteMessage(websocket.TextMessage, []byte(""))
|
||||||
ErrMsg(err)
|
ErrMsg(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -175,6 +175,10 @@ export function useAppContext(websocket) {
|
|||||||
ws.current = createWebsocket(protocol + window.location.host + "/status?mode=ring");
|
ws.current = createWebsocket(protocol + window.location.host + "/status?mode=ring");
|
||||||
ws.current.onmessage = (ev) => {
|
ws.current.onmessage = (ev) => {
|
||||||
try {
|
try {
|
||||||
|
if (ev.data == '') {
|
||||||
|
appLogout(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
let activity = JSON.parse(ev.data);
|
let activity = JSON.parse(ev.data);
|
||||||
updateState({ status: 'connected' });
|
updateState({ status: 'connected' });
|
||||||
if (activity.revision) {
|
if (activity.revision) {
|
||||||
|
Loading…
Reference in New Issue
Block a user