Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/commands/auth/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@ export default class Login extends Command {
'api-key': Flags.string({
description: 'API key (if not provided, you will be prompted)',
}),
'api-url': Flags.string({
description: 'Override the API base URL',
env: 'DATABOX_API_URL',
hidden: true,
}),
}

async run(): Promise<void> {
const {flags} = await this.parse(Login)

let apiKey = flags['api-key']
const apiUrl = flags['api-url']

if (!apiKey) {
apiKey = await prompt('Enter your API key', {mask: true})
Expand All @@ -32,10 +38,11 @@ export default class Login extends Command {
}

const existingConfig = loadConfig()
saveConfig({...existingConfig, apiKey})
const baseUrl = apiUrl ?? existingConfig.apiUrl
saveConfig({...existingConfig, apiKey, apiUrl: baseUrl})

try {
const client = new ApiClient({apiKey, baseUrl: existingConfig.apiUrl})
const client = new ApiClient({apiKey, baseUrl})
await client.get('/v1/auth/validate-key')
this.log('Authenticated successfully.')
} catch {
Expand Down