mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +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 { useNavigate } from 'react-router-dom';
|
||||
import { Alert } from 'react-native';
|
||||
import { setLogin } from 'api/setLogin';
|
||||
import { clearLogin } from 'api/clearLogin';
|
||||
@ -24,6 +25,9 @@ export function useAppContext() {
|
||||
adminToken: null,
|
||||
version: getVersion(),
|
||||
});
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const store = useContext(StoreContext);
|
||||
const account = useContext(AccountContext);
|
||||
const profile = useContext(ProfileContext);
|
||||
@ -164,6 +168,7 @@ export function useAppContext() {
|
||||
await store.actions.clearSession();
|
||||
await store.actions.clearFirstRun();
|
||||
updateState({ loggingOut: false });
|
||||
navigate('/');
|
||||
},
|
||||
remove: async () => {
|
||||
if (!access.current) {
|
||||
@ -179,6 +184,10 @@ export function useAppContext() {
|
||||
const setWebsocket = (session) => {
|
||||
ws.current = createWebsocket(`wss://${session.server}/status?mode=ring`);
|
||||
ws.current.onmessage = (ev) => {
|
||||
if (ev.data == '') {
|
||||
actions.logout();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
delay.current = 0;
|
||||
let activity = JSON.parse(ev.data);
|
||||
|
@ -128,7 +128,6 @@ export function useProfile() {
|
||||
const actions = {
|
||||
logout: async () => {
|
||||
await app.actions.logout();
|
||||
navigate('/');
|
||||
},
|
||||
remove: async () => {
|
||||
await app.actions.remove();
|
||||
|
@ -57,6 +57,7 @@ func Status(w http.ResponseWriter, r *http.Request) {
|
||||
// retrieve reference account
|
||||
var session store.Session
|
||||
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)
|
||||
return
|
||||
}
|
||||
|
@ -175,6 +175,10 @@ export function useAppContext(websocket) {
|
||||
ws.current = createWebsocket(protocol + window.location.host + "/status?mode=ring");
|
||||
ws.current.onmessage = (ev) => {
|
||||
try {
|
||||
if (ev.data == '') {
|
||||
appLogout(false);
|
||||
return;
|
||||
}
|
||||
let activity = JSON.parse(ev.data);
|
||||
updateState({ status: 'connected' });
|
||||
if (activity.revision) {
|
||||
|
Loading…
Reference in New Issue
Block a user