]> Repos - mime-chat/commitdiff
fix auth bug [FE]
authorriqo <hernandeze2@xavier.edu>
Sat, 27 Feb 2021 19:42:53 +0000 (13:42 -0600)
committerriqo <hernandeze2@xavier.edu>
Sat, 27 Feb 2021 19:42:53 +0000 (13:42 -0600)
src/modules/auth.ts

index 05bcbbe8263f8f87ddaad59fe164c570f9e986d3..6a1120e1daaf8071a34828d50f58f2957feaf84b 100644 (file)
@@ -14,16 +14,23 @@ const state = reactive<AuthState>({
 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) => {