@@ -6,7 +6,7 @@ import * as readline from 'node:readline'
66
77export default class AuthLogin extends Command {
88 static description = 'Authenticate with the DevHelm API'
9- static examples = [ '<%= config.bin %> auth login' , '<%= config.bin %> auth login --token sk_live_ ...' ]
9+ static examples = [ '<%= config.bin %> auth login' , '<%= config.bin %> auth login --token dh_live_ ...' ]
1010 static flags = {
1111 ...globalFlags ,
1212 token : Flags . string ( { description : 'API token (skips interactive prompt)' } ) ,
@@ -23,14 +23,35 @@ export default class AuthLogin extends Command {
2323 const apiUrl = flags [ 'api-url' ] || resolveApiUrl ( )
2424 this . log ( 'Validating token...' )
2525 const client = createApiClient ( { baseUrl : apiUrl , token} )
26+
27+ // Try /api/v1/auth/me first (API key — returns rich identity info).
28+ // Falls back to /api/v1/dashboard/overview for non-API-key tokens (dev tokens, JWTs).
2629 try {
2730 // eslint-disable-next-line @typescript-eslint/no-explicit-any
28- const me = await checkedFetch ( client . GET ( '/platform/me' as any , { } as any ) )
31+ const resp = await checkedFetch ( client . GET ( '/api/v1/auth/me' as any , { } as any ) )
32+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
33+ const me = ( resp as any ) ?. data ?? resp
34+
35+ saveContext ( { name : flags . name , apiUrl, token} , true )
36+ this . log ( '' )
37+ this . log ( ` Authenticated successfully.` )
38+ this . log ( ` Organization: ${ me . organization ?. name ?? 'unknown' } (ID: ${ me . organization ?. id ?? '?' } )` )
39+ this . log ( ` Key: ${ me . key ?. name ?? 'unknown' } ` )
40+ this . log ( ` Plan: ${ me . plan ?. tier ?? 'unknown' } ` )
41+ this . log ( '' )
42+ this . log ( ` Context '${ flags . name } ' saved to ~/.devhelm/contexts.json` )
43+ return
44+ } catch {
45+ // /auth/me failed — might be a non-API-key token; try basic validation
46+ }
47+
48+ try {
2949 // eslint-disable-next-line @typescript-eslint/no-explicit-any
30- const email = ( me as any ) ?. data ?. email ?? ( me as any ) ?. email
50+ await checkedFetch ( client . GET ( '/api/v1/dashboard/overview' as any , { } as any ) )
3151 saveContext ( { name : flags . name , apiUrl, token} , true )
32- this . log ( `\nAuthenticated as ${ email } ` )
33- this . log ( `Context '${ flags . name } ' saved to ~/.devhelm/contexts.json` )
52+ this . log ( '' )
53+ this . log ( ` Authenticated successfully.` )
54+ this . log ( ` Context '${ flags . name } ' saved to ~/.devhelm/contexts.json` )
3455 } catch {
3556 this . error ( 'Invalid token. Authentication failed.' , { exit : 2 } )
3657 }
0 commit comments