Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions packages/insomnia/src/account/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ export async function absorbKey(sessionId: string, key: string) {
getUserProfile({ sessionId: sessionIdResolved }),
getEncryptionKeys({ sessionId: sessionIdResolved }),
]);
const {
public_key: publicKey,
enc_private_key: encPrivateKey,
enc_symmetric_key: encSymmetricKey,
} = keys;
const { public_key: publicKey, enc_private_key: encPrivateKey, enc_symmetric_key: encSymmetricKey } = keys;
const { email, id: accountId, first_name: firstName, last_name: lastName } = profile;
const symmetricKeyStr = crypt.decryptAES(key, JSON.parse(encSymmetricKey));

Expand All @@ -46,7 +42,7 @@ export async function absorbKey(sessionId: string, key: string) {
JSON.parse(encPrivateKey),
);

window.main.loginStateChange();
window.main.loginStateChange(true);
}
Comment on lines 43 to 46

export async function getPrivateKey() {
Expand Down Expand Up @@ -97,7 +93,7 @@ export async function logout(clearCredentials = false) {
if (clearCredentials) {
await _removeAllCredentials();
}
window.main.loginStateChange();
window.main.loginStateChange(false);
}

/** Set data for the new session and store it encrypted with the sessionId */
Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia/src/entry.preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ const main: Window['main'] = {
completeExecutionStep: options => ipcRenderer.send('completeExecutionStep', options),
updateLatestStepName: options => ipcRenderer.send('updateLatestStepName', options),
getExecution: options => invokeWithNormalizedError('getExecution', options),
loginStateChange: () => ipcRenderer.send('loginStateChange'),
loginStateChange: options => ipcRenderer.send('loginStateChange', options),
restart: () => ipcRenderer.send('restart'),
openInBrowser: options => ipcRenderer.send('openInBrowser', options),
openDeepLink: options => ipcRenderer.send('openDeepLink', options),
Expand Down
6 changes: 3 additions & 3 deletions packages/insomnia/src/main/ipc/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ const writeResponseBodyToFile = async (
};

export interface RendererToMainBridgeAPI {
loginStateChange: () => void;
loginStateChange: (isLoggedIn: boolean) => void;
openInBrowser: (url: string) => void;
restart: () => void;
halfSecondAfterAppStart: () => void;
Expand Down Expand Up @@ -278,9 +278,9 @@ export function registerMainHandlers() {
ipcMainHandle('multipartBufferToArray', async (_, options) => {
return multipartBufferToArray(options);
});
ipcMainOn('loginStateChange', async () => {
ipcMainOn('loginStateChange', async (_, isLoggedIn: boolean) => {
BrowserWindow.getAllWindows().forEach(w => {
w.webContents.send('loggedIn');
w.webContents.send('loggedIn', isLoggedIn);
});
Comment on lines +281 to 284
});
ipcMainHandle('backup', async () => {
Expand Down
18 changes: 16 additions & 2 deletions packages/insomnia/src/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,26 @@ const Root = () => {
const latestInSubmission = useLatest(ifInSubmission);

useEffect(() => {
return window.main.on('git.db-synced', () => {
const unsubLoggedIn = window.main.on('loggedIn', (_, isLoggedIn: boolean) => {
if (!latestInSubmission.current) {
if (!isLoggedIn) {
// If the user just logged out, navigate to the login page
navigate(href('/auth/login'));
} else {
navigate(href('/organization'));
}
}
});
const unsubGitDbSynced = window.main.on('git.db-synced', () => {
if (!latestInSubmission.current) {
revalidate();
}
});
}, [latestInSubmission, revalidate]);
return () => {
unsubLoggedIn();
unsubGitDbSynced();
};
}, [latestInSubmission, revalidate, navigate]);

useEffect(() => {
return window.main.on('shell:open', async (_: IpcRendererEvent, url: string) => {
Expand Down
Loading