• Cancels ongoing OAuth authentication flow

    Safely aborts an in-progress authentication flow by:

    1. Rejecting the authentication promise with a cancellation error
    2. Shutting down the temporary callback server
    3. Closing the authentication browser window
    4. Cleaning up all related resources and state
    5. Logging the cancellation for debugging purposes

    This function can be called at any point during the authentication process, ensuring all resources are properly cleaned up regardless of the flow state. It provides a graceful way to handle user-initiated cancellations or application-driven authentication termination.

    No action is taken if there isn't an active authentication flow in progress.

    Returns void

    // Cancel authentication when user clicks a cancel button
    cancelButton.addEventListener('click', () => {
    cancelAuthFlow();
    showMessage("Authentication cancelled");
    });

    // Cancel authentication during application shutdown
    app.on('before-quit', () => {
    cancelAuthFlow();
    });
    export function cancelAuthFlow(): void {
    if (authPromiseReject) {
    authPromiseReject(new Error("Authentication canceled"));
    authPromiseReject = null;
    }

    shutdownServer();
    closeAuthWindow();
    saveLog("Authentication flow canceled", "DEBUG");
    }