fix auth on reconnect
This commit is contained in:
parent
20140b16b4
commit
41562c8d4b
2 changed files with 7 additions and 3 deletions
|
|
@ -129,7 +129,8 @@ export function initSession(): void {
|
|||
});
|
||||
|
||||
socket.on('close', () => {
|
||||
console.log('Connection droped! Restarting...')
|
||||
console.log('Connection droped! Restarting...');
|
||||
auth = false;
|
||||
initSession();
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { reactive, toRefs, ref } from 'vue';
|
||||
import { reactive, toRefs } from 'vue';
|
||||
import { useIpc } from './ipc';
|
||||
|
||||
interface AuthState {
|
||||
|
|
@ -13,7 +13,9 @@ const state = reactive<AuthState>({
|
|||
|
||||
const AUTH_KEY = 'crimata_token';
|
||||
|
||||
const token = window.localStorage.getItem(AUTH_KEY);
|
||||
let token: string | null;
|
||||
|
||||
token = window.localStorage.getItem(AUTH_KEY);
|
||||
if (token) {
|
||||
state.accessToken = token;
|
||||
window.localStorage.setItem(AUTH_KEY, token);
|
||||
|
|
@ -22,6 +24,7 @@ if (token) {
|
|||
const authToken = async () => {
|
||||
const { invoke } = useIpc();
|
||||
try {
|
||||
token = window.localStorage.getItem(AUTH_KEY);
|
||||
const res = await invoke('auth-session', token);
|
||||
window.localStorage.setItem(AUTH_KEY, res);
|
||||
state.accessToken = res;
|
||||
|
|
|
|||
Loading…
Reference in a new issue