Skip to content

Commit 6f7259d

Browse files
Add openLoginWindow() promise that resolves when auth token is stored
Agent-Logs-Url: https://github.com/highperformancecoder/minsky/sessions/f860580e-1854-46ba-96ed-117e3d0cfdce Co-authored-by: highperformancecoder <3075825+highperformancecoder@users.noreply.github.com>
1 parent f9b417d commit 6f7259d

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

gui-js/apps/minsky-electron/src/app/events/electron.events.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,38 @@ export default class ElectronEvents {
3939
}
4040
}
4141

42+
// Pending resolver for the auth-token promise created by openLoginWindow()
43+
let _resolveAuthToken: ((token: string | null) => void) | null = null;
44+
45+
/**
46+
* Open the Clerk login popup and return a Promise that resolves with the JWT
47+
* token once the user successfully authenticates (or null if the window is
48+
* closed before authentication completes).
49+
*/
50+
export function openLoginWindow(): Promise<string | null> {
51+
const promise = new Promise<string | null>((resolve) => {
52+
_resolveAuthToken = resolve;
53+
});
54+
55+
const loginWindow = WindowManager.createPopupWindowWithRouting({
56+
width: 420,
57+
height: 500,
58+
title: 'Login',
59+
modal: false,
60+
url: '#/headless/login',
61+
});
62+
63+
// Resolve with null if the user closes the window before authenticating
64+
loginWindow.once('closed', () => {
65+
if (_resolveAuthToken) {
66+
_resolveAuthToken(null);
67+
_resolveAuthToken = null;
68+
}
69+
});
70+
71+
return promise;
72+
}
73+
4274
ipcMain.handle(events.LOG_MESSAGE, async (event, message: string)=>{
4375
return await CppClass.logMessage(message);
4476
});
@@ -295,5 +327,9 @@ ipcMain.handle(events.SET_AUTH_TOKEN, async (event, token: string | null) => {
295327
} else {
296328
StoreManager.store.delete('authToken');
297329
}
330+
if (_resolveAuthToken) {
331+
_resolveAuthToken(token);
332+
_resolveAuthToken = null;
333+
}
298334
return { success: true };
299335
});

gui-js/apps/minsky-electron/src/app/managers/ApplicationMenuManager.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { StoreManager } from './StoreManager';
1717
import { WindowManager } from './WindowManager';
1818
import { BookmarkManager } from './BookmarkManager';
1919
import { RecordingManager } from './RecordingManager';
20+
import { openLoginWindow } from '../events/electron.events';
2021

2122
//TODO:: Remove hardcoding of popup dimensions
2223

@@ -129,14 +130,8 @@ export class ApplicationMenuManager {
129130
},
130131
{
131132
label: 'Login via Clerk',
132-
click() {
133-
WindowManager.createPopupWindowWithRouting({
134-
width: 420,
135-
height: 500,
136-
title: 'Login',
137-
modal: false,
138-
url: '#/headless/login',
139-
});
133+
async click() {
134+
await openLoginWindow();
140135
},
141136
},
142137

0 commit comments

Comments
 (0)