From 41562c8d4bd040badbbae048199c2a59dcb759f5 Mon Sep 17 00:00:00 2001 From: riqo Date: Wed, 10 Mar 2021 09:51:29 -0600 Subject: [PATCH] fix auth on reconnect --- src/background/session.ts | 3 ++- src/modules/auth.ts | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/background/session.ts b/src/background/session.ts index 2179357..ac0c162 100644 --- a/src/background/session.ts +++ b/src/background/session.ts @@ -129,7 +129,8 @@ export function initSession(): void { }); socket.on('close', () => { - console.log('Connection droped! Restarting...') + console.log('Connection droped! Restarting...'); + auth = false; initSession(); }); diff --git a/src/modules/auth.ts b/src/modules/auth.ts index 161545e..04ce66a 100644 --- a/src/modules/auth.ts +++ b/src/modules/auth.ts @@ -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({ 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; -- 2.43.0