• Persists authentication tokens to encrypted storage

    Parameters

    • tokenData: TokenData

      Token data to encrypt and store

    Returns boolean

    Boolean indicating operation success

    export function saveTokens(tokenData: TokenData): boolean {
    try {
    const tokenFilePath = getTokenFilePath();
    const tokenDataString = JSON.stringify(tokenData);

    // Encrypt token data
    const { encryptedData, iv } = encrypt(tokenDataString);

    // Prepare storage structure
    const storageData = {
    encryptedData,
    iv,
    };

    // Write to encrypted storage
    fs.writeFileSync(tokenFilePath, JSON.stringify(storageData));

    saveLog("Spotify tokens saved securely to disk", "DEBUG");

    return true;
    } catch (error) {
    saveLog(`Failed to save tokens: ${error}`, "ERROR");
    return false;
    }
    }