@@ -385,6 +385,32 @@ export class WindowManager {
385385 }
386386 }
387387
388+ // Derive the Clerk frontendApi hostname from the publishable key.
389+ // Key format: pk_<type>_<base64(frontendApi + '$')>
390+ static clerkApi ( ) : string {
391+ // const encoded = CLERK_PUBLISHABLE_KEY.split('_')[2] ?? '';
392+ // const padded = encoded + '='.repeat((4 - (encoded.length % 4)) % 4);
393+ // return Buffer.from(padded, 'base64').toString('utf8').replace(/\$$/, '');
394+ return 'positive-phoenix-85.accounts.dev' ;
395+ }
396+
397+ static clerkLogout ( ) {
398+ const loginWindow = new BrowserWindow ( {
399+ width : 480 ,
400+ height : 640 ,
401+ title : 'Sign In' ,
402+ parent : WindowManager . getMainWindow ( ) ,
403+ modal : false ,
404+ webPreferences : {
405+ contextIsolation : true ,
406+ nodeIntegration : false ,
407+ } ,
408+ icon : __dirname + '/assets/favicon.png' ,
409+ } ) ;
410+ console . log ( `https://${ WindowManager . clerkApi ( ) } /sign-out` ) ;
411+ loginWindow . loadURL ( `https://${ WindowManager . clerkApi ( ) } /sign-out` ) ;
412+ }
413+
388414 static async openLoginWindow ( ) : Promise < string | null > {
389415 // Open Clerk's Accounts Portal sign-in page in a dedicated BrowserWindow.
390416 // Passing __publishable_key tells Clerk which app to authenticate against —
@@ -397,9 +423,23 @@ export class WindowManager {
397423 // ('minsky://signed-in'). We intercept that navigation with will-navigate,
398424 // execute JS in the still-live sign-in page to obtain a JWT from
399425 // window.Clerk.session.getToken(), stash it, and close the window.
400- const redirectUrl = 'minsky://signed-in' ;
401- const signInUrl = `https://accounts.clerk.com/sign-in?__publishable_key=${ encodeURIComponent ( CLERK_PUBLISHABLE_KEY ) } &redirect_url=${ encodeURIComponent ( redirectUrl ) } ` ;
402426
427+ // This is a dummy URL. It needs to be something like this form for Clerk to redirect back to here
428+ const redirectUrl = '/headless/sign-in' ;
429+ let frontendApi : string ;
430+ try {
431+ frontendApi = WindowManager . clerkApi ( ) ;
432+ } catch {
433+ log . error ( 'WindowManager.openLoginWindow: invalid Clerk publishable key' ) ;
434+ return Promise . resolve ( null ) ;
435+ }
436+
437+ //https://positive-phoenix-85.accounts.dev
438+
439+ const signInUrl = `https://${ frontendApi } /sign-in?&redirect_url=${ encodeURIComponent ( redirectUrl ) } ` ;
440+ //const signInUrl = `https://${frontendApi}/sign-in`;
441+
442+ console . log ( signInUrl ) ;
403443 return new Promise < string > ( ( resolve ) => {
404444 const loginWindow = new BrowserWindow ( {
405445 width : 480 ,
@@ -418,7 +458,8 @@ export class WindowManager {
418458 loginWindow . once ( 'ready-to-show' , ( ) => loginWindow . show ( ) ) ;
419459
420460 loginWindow . webContents . on ( 'will-navigate' , async ( event , url ) => {
421- if ( url . startsWith ( 'minsky://' ) ) {
461+ console . log ( 'will-navigate' , url ) ;
462+ /*if (url.startsWith('https://explore'))*/ {
422463 // The sign-in page is about to redirect to our custom scheme, meaning
423464 // sign-in completed successfully. Prevent the navigation (the minsky://
424465 // scheme is not registered as a real protocol), then extract the JWT
0 commit comments