• Exchange an authorization code for an access token through the main process.

    Parameters

    • clientId: string

      The OAuth client ID.

    • clientSecret: string

      The OAuth client secret.

    • redirectUri: string

      The redirect URI used for authentication.

    • code: string

      The authorization code to exchange.

    Returns Promise<{ access_token: string; token_type: string; expires_in: number }>

    Promise resolving to the token response.

    export async function getAccessToken(
    clientId: string,
    clientSecret: string,
    redirectUri: string,
    code: string,
    ): Promise<{ access_token: string; token_type: string; expires_in: number }> {
    console.log("🔑 getAccessToken starting with:", {
    clientId: clientId.substring(0, 2) + "...",
    redirectUri,
    codeLength: code.length,
    });

    // Use the main process to exchange the token
    const result = await window.electronAPI.anilist.exchangeToken({
    clientId,
    clientSecret,
    redirectUri,
    code,
    });

    if (!result.success || !result.token) {
    throw new Error(
    `Failed to exchange code for token: ${result.error || "Unknown error"}`,
    );
    }

    return result.token;
    }