Skip to content

Commit 07f5c4c

Browse files
committed
feat: region selection before login
1 parent 15764a8 commit 07f5c4c

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

packages/stack/src/bin/commands/auth/index.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { login } from './login.js'
2-
import { bindDevice } from './login.js'
1+
import { bindDevice, login, selectRegion } from './login.js'
32

43
const HELP = `
54
Usage: stash auth <command>
@@ -20,9 +19,11 @@ export async function authCommand(args: string[]) {
2019
}
2120

2221
switch (subcommand) {
23-
case 'login':
24-
await login()
22+
case 'login': {
23+
const region = await selectRegion()
24+
await login(region)
2525
await bindDevice()
26+
}
2627
break
2728
default:
2829
console.error(`Unknown auth command: ${subcommand}\n`)

packages/stack/src/bin/commands/auth/login.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,35 @@ import * as p from '@clack/prompts'
22
import auth from '@cipherstash/auth'
33
const { beginDeviceCodeFlow, bindClientDevice } = auth
44

5-
export async function login() {
5+
// TODO: pull from the CTS API
6+
export const regions = [
7+
{ value: 'ap-southeast-2.aws', label: 'Asia Pacific (Sydney)' },
8+
{ value: 'eu-central-1.aws', label: 'Europe (Frankfurt)' },
9+
{ value: 'eu-west-1.aws', label: 'Europe (Ireland)' },
10+
{ value: 'us-east-1.aws', label: 'US East (N. Virginia)' },
11+
{ value: 'us-east-2.aws', label: 'US East (Ohio)' },
12+
{ value: 'us-west-1.aws', label: 'US West (N. California)' },
13+
{ value: 'us-west-2.aws', label: 'US West (Oregon)' },
14+
]
15+
16+
export async function selectRegion(): Promise<string> {
17+
const region = await p.select({
18+
message: 'Select a region',
19+
options: regions,
20+
})
21+
22+
if (p.isCancel(region)) {
23+
p.cancel('Cancelled.')
24+
process.exit(0)
25+
}
26+
27+
return region
28+
}
29+
30+
export async function login(region: string) {
631
const s = p.spinner()
732

8-
const pending = await beginDeviceCodeFlow('ap-southeast-2.aws', 'cli')
33+
const pending = await beginDeviceCodeFlow(region, 'cli')
934

1035
p.log.info(`Your code is: ${pending.userCode}`)
1136
p.log.info(`Visit: ${pending.verificationUriComplete}`)

packages/stack/src/bin/commands/init/steps/authenticate.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import { bindDevice, login } from '../../auth/login.js'
1+
import { bindDevice, login, selectRegion } from '../../auth/login.js'
22
import type { InitProvider, InitState, InitStep } from '../types.js'
33

44
export const authenticateStep: InitStep = {
55
id: 'authenticate',
66
name: 'Authenticate with CipherStash',
77
async run(state: InitState, _provider: InitProvider): Promise<InitState> {
8-
await login()
8+
const region = await selectRegion()
9+
await login(region)
910
await bindDevice()
1011
return { ...state, authenticated: true }
1112
},

0 commit comments

Comments
 (0)