]> Repos - mime-chat/commitdiff
update account endpoints
authorEnrique Hernandez <hernandeze2@xavier.edu>
Thu, 17 Jun 2021 13:51:13 +0000 (08:51 -0500)
committerEnrique Hernandez <hernandeze2@xavier.edu>
Thu, 17 Jun 2021 13:51:13 +0000 (08:51 -0500)
src/account.ts
src/api/account.ts
src/composables/useIpcMain.ts
src/config.ts
src/ipc/account.ts
src/ipc/index.ts
src/render/App.vue
src/render/components/login.vue
src/render/components/settings.vue
src/render/composables/useProfile.ts
src/render/ipc.ts

index 95fe6298973c9b0b6ac561b7b1c7f4c7c4a0f741..9f867f64ec716465753b61c5580dd0534135bec9 100644 (file)
@@ -44,10 +44,10 @@ export const accountLogin: IpcHandlerCallback<AccountCredentials, Profile> = asy
          const parsed = parseAuthRes(res);
 
          // save jwt token and profile
-         setToken(parsed.token)
+         setToken(parsed.token);
 
          // launch session
-         launchSession(parsed.token)
+         launchSession(parsed.token);
 
          // return profile to renderer
          return parsed.profile;
index 59872c8020e5d68bdebccb61fb76163e6d045f1a..45baca22089e5507d56344afffb2b1c2e6fdba1e 100644 (file)
@@ -9,16 +9,16 @@ export const postAuth = async (token: string) => (
     await axios({
         url: config.BUSINESS_URL + config.BUSINESS_PREFIX + '/account/authenticate',
         headers: {
-            Cookie: `jwt=${token}`
+            Cookie: `crimataCookie=${token}`
         },
         method: 'POST',
     })
-).data;
+);
 
 
 export const postLogin = async (email: string, password: string) => (
     await post('/account/login', { email, password })
-).data;
+);
 
 
 export const postLogout =
index b5881024e50385b528656d36c16fe341ab2fe123..0a187b7ebdd7fe8789b062d2bde03fcad5ba9aa4 100644 (file)
@@ -16,6 +16,8 @@ export class IpcHandler<InputType, ReturnType> implements IIpcHandler<InputType,
   }
 
   handle() {
+      console.log(`[IPC] INIT:${this.channel}`);
+      this.remove();
       ipcMain.handle(this.channel, this._onInvoke);
   }
 
@@ -23,11 +25,11 @@ export class IpcHandler<InputType, ReturnType> implements IIpcHandler<InputType,
       ipcMain.removeHandler(this.channel);
   }
 
-  private async _onInvoke(_e: IpcMainInvokeEvent, payload?: string | null): Promise<Error | ReturnType> {
+  private _onInvoke = (_e: IpcMainInvokeEvent, payload?: string | null): Promise<Error | ReturnType> => {
 
       return new Promise(async (resolve, reject) => {
 
-          console.log(`[IPC]:${this.channel}`);
+          console.log(`[IPC] Handle:${this.channel}`);
 
           try {
 
@@ -38,7 +40,7 @@ export class IpcHandler<InputType, ReturnType> implements IIpcHandler<InputType,
               resolve(res as unknown as ReturnType);
 
           } catch(e) {
-              console.log(`[IPC]:${this.channel}`, e);
+              console.log(`[IPC] Error:${this.channel}`);
               reject(e);
           }
       });
@@ -48,3 +50,6 @@ export class IpcHandler<InputType, ReturnType> implements IIpcHandler<InputType,
 
 
 
+
+
+
index b0eb27ef46dc2f3193d0839a5cc08be219eb196a..855b1b2d3f2d559da367d8f63ab2da0c137c9854 100644 (file)
@@ -6,7 +6,7 @@ const env = process.env;
 const PLATFORM_PORT = env.PLATFORM_PORT || 8760;
 const PLATFORM_IP = env.PLATFORM_IP || 'http://127.0.0.1';
 
-const BUSINESS_PORT = env.BUSINESS_PORT || 3010;
+const BUSINESS_PORT = env.BUSINESS_PORT || 3000;
 const BUSINESS_IP = env.BUSINESS_IP || 'http://127.0.0.1';
 
 export const config = {
index 7759d12afde510f4eb6d2fad32b6869b8dfad43a..29a614b3720e1b4034baab7af77b5ef69a661333 100644 (file)
@@ -2,7 +2,7 @@
 "use strict";
 
 import { accountLogin, accountLogout } from "@/account";
-import {IpcHandler} from "@/composables/useIpcMain";
+import { IpcHandler } from "@/composables/useIpcMain";
 
 const LOGIN_CHANNEL = "account-login";
 const LOGOUT_CHANNEL = "account-logout";
index 73a5901c8236b0c3186bc229283ce8cc2cfdd7d6..ef61fe91dd8f338c6f461661e25293b1f0050eda 100644 (file)
@@ -1,7 +1,7 @@
 
 "use strict";
 
-import { IpcHandler } from "@/composables/ipcHandler";
+import {IpcHandler} from "@/composables/useIpcMain";
 import handlers from "./account";
 import useSessionListeners from "./session";
 // import useAudioListeners from "./audio";
index dfdaeb916ef5f410ef39ed097b844e155247b850..2794eaad7bdb8a7f7c3adcb987d357dd690b699e 100644 (file)
@@ -1,13 +1,13 @@
 <template>
   <!-- Only render when profile has been set -->
-  <main id="app" v-if="typeof profile !== 'undefined'">
+  <main id="app" v-if="ready">
 
     <Header />
 
     <!-- Main Components -->
     <Messenger
-      v-if="state.profile"
-      :profile="state.profile"
+      v-if="profile"
+      :profile="profile"
       :messages="state.messages"
     />
     <Login v-else />
 <script lang="ts">
 
 import { defineComponent, onMounted, onUnmounted, Ref, ref } from "vue";
-import { invokeProfile } from "@/render/ipc";
+import { IpcRendererEvent } from "electron";
 
 import Splash from "@/render/components/splash.vue";
 import Messenger from "@/render/components/messenger.vue";
 import Login from "@/render/components/login.vue";
 import Header from "@/render/components/header.vue";
+import useProfile from "@/render/composables/useProfile";
 
 export default defineComponent({
 
@@ -40,24 +41,29 @@ export default defineComponent({
 
   setup() {
 
-    const crimataId = ref(false);
+    const ready = ref(false);
+
+    const { setProfile, clearProfile, profile } = useProfile();
 
     onMounted(async () => {
       console.log("[APP]:mounted.");
 
       /* listen for auth related messages */
-      window.addEventListener("update-auth", (event: any) => {
-        // state.value = event.data;
+      window.ipcRenderer.on("set-profile", (_event: IpcRendererEvent, payload: any) => {
+        payload.message ? setProfile(payload.message) : clearProfile();
+        ready.value = true;
+        console.log('progfile', profile.value)
       });
 
     });
 
     onUnmounted(() => {
-      window.ipcRenderer.removeAllListeners("update-state");
+      window.ipcRenderer.removeAllListeners("set-profile");
     });
 
     return {
-        crimataId
+        ready,
+        profile
     }
   }
 })
index b54d471e3d9b586cbfc88e76b5e4caddbaa19967..9970f4cdf836984a289035296a8d020ee3348d51 100644 (file)
@@ -35,7 +35,7 @@
 <script lang="ts">
 
 import { defineComponent, ref } from "vue";
-import { useProfile } from '@/render/composables/useProfile';
+import useProfile from '@/render/composables/useProfile';
 import { invokeLogin } from "@/render/ipc";
 
 export default defineComponent({
index c6933566dccb5640d872669ef7a2bf3da0401644..46e14bd78ba55ba2e438efcbdd6707545f2373dc 100644 (file)
@@ -28,7 +28,7 @@
 <script lang="ts">
 
   import { defineComponent, ref } from "vue";
-  import { useProfile } from "@/render/composables/useProfile"
+  import useProfile from "@/render/composables/useProfile"
   import { invokeLogout } from "@/render/ipc";
 
   export default defineComponent({
index e813dadcc40bd684f8c7d971cd7cebfa3493d63e..0ee3b6db6dc7a9a08cf1dd45b8b33e2787b1f45c 100644 (file)
@@ -2,12 +2,10 @@ import { ref } from "vue";
 
 const profile = ref();
 
-export const useProfile = () => {
+const useProfile = () => {
 
     const setProfile = (payload: Profile) => {
         profile.value = payload;
-        /* emit event to app.vue */
-        window.postMessage(profile, 'profile');
     }
 
     const clearProfile = () => {
@@ -21,3 +19,5 @@ export const useProfile = () => {
     }
 
 }
+
+export default  useProfile;
index 7a7e1dc7118816a16c5785935c7f5f490f9b4905..9a8e47819efea58c7493674ee3fae5a28f4f89d0 100644 (file)
@@ -9,18 +9,15 @@ const { post, invoke } = useIpc();
  *
  */
 
-export const invokeProfile = async (): Promise<Profile | Error> => (
-    await invoke('user-profile', null)
-);
 
 export const invokeLogin = async (
     payload: LoginPayload
 ): Promise<Profile | Error> => (
-    await invoke('user-login', JSON.stringify(payload))
+    await invoke('account-login', JSON.stringify(payload))
 );
 
 export const invokeLogout = async (): Promise<void> => (
-    await invoke("user-logout", null)
+    await invoke("account-logout", null)
 );
 
 /**