magically-sdk
Version:
Official SDK for Magically - Build mobile apps with AI
22 lines (21 loc) • 850 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAuthToken = getAuthToken;
/**
* Get the appropriate authentication token based on the environment
*
* In edge environments (Cloudflare Workers), the API key is used automatically
* and no token needs to be passed. In browser/Node environments, we need to
* get the JWT token from the auth system.
*
* @param apiClient - The APIClient instance to check for edge environment
* @param auth - The MagicallyAuth instance to get JWT token from
* @returns The token to use (null in edge environment, JWT string otherwise)
*/
async function getAuthToken(apiClient, auth) {
// In edge environment, API key is used automatically
// Otherwise, get user token
return apiClient.isEdgeEnvironment()
? null
: await auth.getValidToken();
}