mirror of
https://github.com/steel-dev/cli.git
synced 2026-09-14 20:47:34 +08:00
30 lines
778 B
TypeScript
30 lines
778 B
TypeScript
import {readApiKeyFromConfig} from './apiConfig.js';
|
|
|
|
export type BrowserAuthSource = 'env' | 'config' | 'none';
|
|
|
|
export type BrowserAuthResolution = {
|
|
apiKey: string | null;
|
|
source: BrowserAuthSource;
|
|
};
|
|
|
|
export function resolveBrowserAuth(
|
|
environment: NodeJS.ProcessEnv = process.env,
|
|
configApiKey?: string | null,
|
|
): BrowserAuthResolution {
|
|
const resolvedConfigApiKey =
|
|
configApiKey === undefined
|
|
? readApiKeyFromConfig(environment)
|
|
: configApiKey;
|
|
const environmentApiKey = environment.STEEL_API_KEY?.trim();
|
|
if (environmentApiKey) {
|
|
return {apiKey: environmentApiKey, source: 'env'};
|
|
}
|
|
|
|
const savedApiKey = resolvedConfigApiKey?.trim();
|
|
if (savedApiKey) {
|
|
return {apiKey: savedApiKey, source: 'config'};
|
|
}
|
|
|
|
return {apiKey: null, source: 'none'};
|
|
}
|