add persistent auth session
This commit is contained in:
parent
bf7c0a8445
commit
a7253ebf40
8 changed files with 69 additions and 66 deletions
|
|
@ -40,6 +40,7 @@ const authSession = async (_event, payload: string | UserCreds | null): Promise<
|
|||
if (res === 'locked') {
|
||||
reject(res);
|
||||
} else {
|
||||
console.log('Success!');
|
||||
auth = true;
|
||||
resolve(res);
|
||||
}
|
||||
|
|
@ -48,11 +49,12 @@ const authSession = async (_event, payload: string | UserCreds | null): Promise<
|
|||
|
||||
if (!payload) {
|
||||
socket.send('no-token');
|
||||
} else if (typeof payload === 'string' || payload instanceof String) {
|
||||
} else if (payload instanceof String || typeof payload === 'string') {
|
||||
socket.send(payload);
|
||||
} else {
|
||||
socket.send(JSON.stringify(payload));
|
||||
}
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -95,18 +97,19 @@ export const initSession = () => {
|
|||
socket.binaryType = 'arraybuffer';
|
||||
|
||||
// handle renderer auth-token event
|
||||
ipcMain.removeHandler('auth-user'); // avoid setting duplicate handlers
|
||||
ipcMain.handle('auth-user', authSession);
|
||||
ipcMain.removeHandler('auth-session'); // avoid setting duplicate handlers
|
||||
ipcMain.handle('auth-session', authSession);
|
||||
|
||||
// Connect to the backend.
|
||||
socket.on('open', () => {
|
||||
console.log('Success! Connected to Crimata Servers.');
|
||||
console.log('Connected to Crimata Servers.');
|
||||
|
||||
// fetch token from renderer
|
||||
// call auth renderer event on connection
|
||||
backgroundMitt.emit('ipc-renderer', {
|
||||
endpoint: 'fetch-token',
|
||||
endpoint: 'auth',
|
||||
message: null
|
||||
});
|
||||
|
||||
success = true;
|
||||
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue