remove auth from sesssion
This commit is contained in:
parent
730cb4b31a
commit
fe954f2960
4 changed files with 52 additions and 32 deletions
|
|
@ -41,6 +41,7 @@ import Messenger from "@/components/messenger.vue";
|
|||
import Login from "@/components/login.vue";
|
||||
|
||||
export default defineComponent({
|
||||
|
||||
components: {
|
||||
Splash,
|
||||
Messenger,
|
||||
|
|
@ -72,7 +73,8 @@ export default defineComponent({
|
|||
}
|
||||
|
||||
// Set profile and newMessages.
|
||||
profile.value = payload.message.profile;
|
||||
// profile.value = payload.message.profile;
|
||||
profile.value = true;
|
||||
newMessages.value = payload.message.newMessages;
|
||||
|
||||
ready.value = true;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
|
||||
import { app, dialog } from "electron";
|
||||
import { createWindow } from './window';
|
||||
import { initSession } from './session';
|
||||
import { initSession, updateState } from './session';
|
||||
import { initAudioIO, stopStream } from './audio';
|
||||
import { backgroundMitt } from '@/modules/emitter';
|
||||
|
||||
|
|
@ -15,7 +15,7 @@ backgroundMitt.on('window-active', (state: boolean) => {
|
|||
});
|
||||
|
||||
// Auto updating.
|
||||
const { autoUpdater } = require('electron-updater')
|
||||
const { autoUpdater } = require('electron-updater');
|
||||
autoUpdater.requestHeaders = { 'PRIVATE-TOKEN': 'mvvgWYwWnot4bisiQMh_' }
|
||||
|
||||
autoUpdater.on('update-available', (info: any) => {
|
||||
|
|
@ -38,6 +38,13 @@ autoUpdater.on('update-downloaded', (info: any) => {
|
|||
|
||||
})
|
||||
|
||||
|
||||
interface Profile {
|
||||
crimataId: string;
|
||||
alias: string;
|
||||
initials: string;
|
||||
}
|
||||
|
||||
// Run when electron app is initialized.
|
||||
async function main() {
|
||||
console.log("MAIN:Initializing Electron App.")
|
||||
|
|
@ -45,6 +52,17 @@ async function main() {
|
|||
// Must wait til window is created.
|
||||
await createWindow();
|
||||
|
||||
// authenticate against business backend
|
||||
const auth = async (crimataId: string): Promise<Profile | null> => {
|
||||
updateState({key: "", profile: {
|
||||
crimataId: "",
|
||||
alias: "",
|
||||
initials: ""
|
||||
}});
|
||||
return null
|
||||
};
|
||||
auth('');
|
||||
|
||||
// Instantiate socket session with crimata-platorm.
|
||||
initSession();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
/*
|
||||
* Creates a websocket session with Crimata Servers.
|
||||
*
|
||||
* Connects to Servers and attempts key authentication. Server will respond
|
||||
* with key and user profile. We send the profile to the browser. We also
|
||||
* resend this information on new broser window. We then serve as a
|
||||
* communication interface between the window and the servers. It will
|
||||
*
|
||||
* Connects to Servers and attempts key authentication. Server will respond
|
||||
* with key and user profile. We send the profile to the browser. We also
|
||||
* resend this information on new broser window. We then serve as a
|
||||
* communication interface between the window and the servers. It will
|
||||
* automatically try to reconnect on websocket disconnect.
|
||||
*/
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ import useWebSockets from "@/modules/websockets";
|
|||
|
||||
import { play } from "./audio";
|
||||
import { renderMessage } from "@/modules/message";
|
||||
import { AuthProtocol, SessionState, Profile } from "@/types";
|
||||
import { AuthProtocol, SessionState, Profile } from "@/types";
|
||||
|
||||
let win = true;
|
||||
|
||||
|
|
@ -27,7 +27,7 @@ let state: SessionState;
|
|||
let profile: Profile | boolean;
|
||||
|
||||
// Called when server sends auth message.
|
||||
const updateState = (res: AuthProtocol) => {
|
||||
export const updateState = (res: AuthProtocol) => {
|
||||
console.log("SESS:Auth message received: \n" +
|
||||
` key: ${res.key}\n` +
|
||||
` alias: ${res.profile}`)
|
||||
|
|
@ -71,12 +71,10 @@ const onMessage = (data: string) => {
|
|||
let message = JSON.parse(data)
|
||||
|
||||
// AuthProtocol message.
|
||||
if (message.hasOwnProperty("key")) {
|
||||
updateState(message)
|
||||
}
|
||||
updateState(message)
|
||||
|
||||
// Standard message.
|
||||
else if (message.content) {
|
||||
if (message.content) {
|
||||
|
||||
// Convert to render message
|
||||
message = renderMessage(
|
||||
|
|
@ -93,7 +91,7 @@ const onMessage = (data: string) => {
|
|||
}
|
||||
ipcEmit("render-message", message)
|
||||
}
|
||||
|
||||
|
||||
else {
|
||||
console.log("SESS:No window: saving message.")
|
||||
state.newMessages.push(message);
|
||||
|
|
@ -110,14 +108,14 @@ const onMessage = (data: string) => {
|
|||
|
||||
// When socket connects, we update state.
|
||||
const onOpen = () => {
|
||||
console.log(`SESS:Sending key: ${state.key}`)
|
||||
// console.log(`SESS:Sending key: ${state.key}`)
|
||||
|
||||
if (state) {
|
||||
sendMessage({
|
||||
"key": state.key,
|
||||
"usr": false,
|
||||
"pwd": false
|
||||
})
|
||||
// sendMessage({
|
||||
// "key": state.key,
|
||||
// "usr": false,
|
||||
// "pwd": false
|
||||
// })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -128,12 +126,15 @@ const { createSocket, sendMessage } = useWebSockets(onMessage, onOpen);
|
|||
const onClientMessage = (_event: IpcMainEvent, payload: any) => {
|
||||
console.log("New client message")
|
||||
|
||||
const success = sendMessage(payload)
|
||||
if (payload.hasOwnProperty("key")) {
|
||||
return
|
||||
}
|
||||
const success = sendMessage(payload);
|
||||
|
||||
if (!success) {
|
||||
console.log("Unable to send message: ", payload)
|
||||
console.log("Unable to send message: ", payload);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Call this to initialize session with Crimata servers.
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
|
||||
<!-- List of message bubbles. -->
|
||||
<div id="messenger">
|
||||
<Message
|
||||
v-for="message in messages"
|
||||
:message="message[1]"
|
||||
<Message
|
||||
v-for="message in messages"
|
||||
:message="message[1]"
|
||||
:key="message[0]"
|
||||
/>
|
||||
</div>
|
||||
|
|
@ -48,25 +48,24 @@ export default defineComponent({
|
|||
|
||||
// Load the message history.
|
||||
if (crimataId === window.localStorage.getItem("last_usr")) {
|
||||
prepMessageView(props.newMessages)
|
||||
prepMessageView(props.newMessages);
|
||||
} else {
|
||||
messages.value.clear()
|
||||
messages.value.clear();
|
||||
}
|
||||
|
||||
// New content listeners.
|
||||
emitter.on('self-message', (message) => updateMessageView(message));
|
||||
window.ipcRenderer.on("render-message", (_e: any, payload: any) => {
|
||||
updateMessageView(payload.message)
|
||||
updateMessageView(payload.message);
|
||||
});
|
||||
|
||||
// Save the usr for next time.
|
||||
window.localStorage.setItem("last_usr", crimataId)
|
||||
window.localStorage.setItem("last_usr", crimataId);
|
||||
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.ipcRenderer.removeAllListeners("render-message");
|
||||
window.ipcRenderer.removeAllListeners("annotate-message");
|
||||
emitter.all.clear();
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue