From ba2826484f0152936478e307913230a5b834ae8b Mon Sep 17 00:00:00 2001 From: riqo Date: Sat, 27 Feb 2021 13:42:53 -0600 Subject: [PATCH] fix auth bug [FE] --- src/modules/auth.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/modules/auth.ts b/src/modules/auth.ts index 05bcbbe..6a1120e 100644 --- a/src/modules/auth.ts +++ b/src/modules/auth.ts @@ -14,16 +14,23 @@ const state = reactive({ const AUTH_KEY = 'crimata_token'; const token = window.localStorage.getItem(AUTH_KEY); +if (token) { + state.accessToken = token; + window.localStorage.setItem(AUTH_KEY, token); +} const authToken = async () => { const { invoke } = useIpc(); try { - state.accessToken = await invoke('auth-session', token); + const res = await invoke('auth-session', token); + window.localStorage.setItem(AUTH_KEY, res); + state.accessToken = res; } catch(e) { state.error = e; console.log('ERROR: failed authentication'); window.localStorage.removeItem(AUTH_KEY); + state.accessToken = null; } } @@ -32,10 +39,6 @@ window.ipcRenderer.on("auth", async (_event, _arg) => { await authToken(); }); -if (token) { - state.accessToken = token; -} - export const useAuth = () => { const setToken = (token: string) => { -- 2.43.0