Parent application window that owns this authentication dialog
Spotify authorization URL to load in the window
Callback function to execute when window is closed
The created BrowserWindow instance for further customization if needed
// Create authentication window from main application window
const authWindow = createAuthWindow(
mainWindow,
'https://accounts.spotify.com/authorize?client_id=...',
() => console.log('Auth window was closed')
);
export function createAuthWindow(
parentWindow: BrowserWindow,
url: string,
onClose: () => void,
): BrowserWindow {
// Clean up any existing window
if (authWindow) {
closeAuthWindow();
}
// Create a new authentication window
authWindow = new BrowserWindow({
parent: parentWindow,
modal: true,
width: 500,
height: 700,
show: false,
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
},
});
// Configure window properties
authWindow.setMenu(null);
authWindow.setTitle("Spotify Authentication");
// Set up event handlers
authWindow.once("ready-to-show", () => {
if (authWindow) {
authWindow.show();
saveLog("OAuth authentication window displayed", "DEBUG");
}
});
authWindow.webContents.on(
"did-fail-load",
(_, errorCode, errorDescription) => {
saveLog(
`Authentication page failed to load: ${errorDescription} (${errorCode})`,
"ERROR",
);
closeAuthWindow();
onClose();
},
);
authWindow.on("closed", () => {
authWindow = null;
onClose();
});
// Load the authorization URL
authWindow.loadURL(url);
saveLog(`OAuth window created and loading URL: ${url}`, "DEBUG");
return authWindow;
}
Creates and displays a browser window for OAuth authentication
Creates a modal browser window for the Spotify OAuth flow with:
The window is created hidden first, then shown once content has loaded to provide a smoother user experience. Event handlers manage the complete window lifecycle, including error scenarios and cleanup.