update account endpoints

This commit is contained in:
Enrique Hernandez 2021-06-17 08:51:13 -05:00
commit 798b848c9b
11 changed files with 38 additions and 30 deletions

View 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;

View 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 =

View 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,

View 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 = {

View 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";

View 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";

View 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 />
@ -22,12 +22,13 @@
<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
}
}
})

View 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({

View 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({

View 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;

View 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)
);
/**