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;
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 =
}
handle() {
+ console.log(`[IPC] INIT:${this.channel}`);
+ this.remove();
ipcMain.handle(this.channel, this._onInvoke);
}
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 {
resolve(res as unknown as ReturnType);
} catch(e) {
- console.log(`[IPC]:${this.channel}`, e);
+ console.log(`[IPC] Error:${this.channel}`);
reject(e);
}
});
+
+
+
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 = {
"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";
"use strict";
-import { IpcHandler } from "@/composables/ipcHandler";
+import {IpcHandler} from "@/composables/useIpcMain";
import handlers from "./account";
import useSessionListeners from "./session";
// import useAudioListeners from "./audio";
<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({
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
}
}
})
<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({
<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({
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 = () => {
}
}
+
+export default useProfile;
*
*/
-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)
);
/**