@@ -2,88 +2,88 @@ import { buildCommand, numberParser } from "@stricli/core";
22import type { SryContext } from "../../context.js" ;
33import { getConfigPath , isAuthenticated } from "../../lib/config.js" ;
44import {
5- completeOAuthFlow ,
6- performOAuthFlow ,
7- setApiToken ,
5+ completeOAuthFlow ,
6+ performOAuthFlow ,
7+ setApiToken ,
88} from "../../lib/oauth.js" ;
99
1010type LoginFlags = {
11- readonly token ?: string ;
12- readonly timeout : number ;
11+ readonly token ?: string ;
12+ readonly timeout : number ;
1313} ;
1414
1515export const loginCommand = buildCommand ( {
16- docs : {
17- brief : "Authenticate with Sentry" ,
18- fullDescription :
19- "Log in to Sentry using OAuth or an API token. " +
20- "The OAuth flow will open your browser for authentication. " +
21- "Alternatively, use --token to authenticate with an existing API token.\n\n" +
22- "For OAuth, set these environment variables:\n" +
23- " SRY_CLIENT_ID - Your Sentry OAuth app client ID\n" +
24- " SRY_CLIENT_SECRET - Your Sentry OAuth app client secret" ,
25- } ,
26- parameters : {
27- flags : {
28- token : {
29- kind : "parsed" ,
30- parse : String ,
31- brief : "Authenticate using an API token instead of OAuth" ,
32- optional : true ,
33- } ,
34- timeout : {
35- kind : "parsed" ,
36- parse : numberParser ,
37- brief : "Timeout for OAuth flow in seconds (default: 300)" ,
38- default : 300 ,
39- } ,
40- } ,
41- } ,
42- async func ( this : SryContext , flags : LoginFlags ) : Promise < void > {
43- const { process } = this ;
16+ docs : {
17+ brief : "Authenticate with Sentry" ,
18+ fullDescription :
19+ "Log in to Sentry using OAuth or an API token. " +
20+ "The OAuth flow will open your browser for authentication. " +
21+ "Alternatively, use --token to authenticate with an existing API token.\n\n" +
22+ "For OAuth, set these environment variables:\n" +
23+ " SRY_CLIENT_ID - Your Sentry OAuth app client ID\n" +
24+ " SRY_CLIENT_SECRET - Your Sentry OAuth app client secret" ,
25+ } ,
26+ parameters : {
27+ flags : {
28+ token : {
29+ kind : "parsed" ,
30+ parse : String ,
31+ brief : "Authenticate using an API token instead of OAuth" ,
32+ optional : true ,
33+ } ,
34+ timeout : {
35+ kind : "parsed" ,
36+ parse : numberParser ,
37+ brief : "Timeout for OAuth flow in seconds (default: 300)" ,
38+ default : 300 ,
39+ } ,
40+ } ,
41+ } ,
42+ async func ( this : SryContext , flags : LoginFlags ) : Promise < void > {
43+ const { process } = this ;
4444
45- // Check if already authenticated
46- if ( isAuthenticated ( ) ) {
47- process . stdout . write (
48- "You are already authenticated. Use 'sry auth logout' first to re-authenticate.\n"
49- ) ;
50- return ;
51- }
45+ // Check if already authenticated
46+ if ( isAuthenticated ( ) ) {
47+ process . stdout . write (
48+ "You are already authenticated. Use 'sry auth logout' first to re-authenticate.\n" ,
49+ ) ;
50+ return ;
51+ }
5252
53- // Token-based authentication
54- if ( flags . token ) {
55- setApiToken ( flags . token ) ;
56- process . stdout . write ( "✓ Authenticated with API token\n" ) ;
57- process . stdout . write ( ` Config saved to: ${ getConfigPath ( ) } \n` ) ;
58- return ;
59- }
53+ // Token-based authentication
54+ if ( flags . token ) {
55+ setApiToken ( flags . token ) ;
56+ process . stdout . write ( "✓ Authenticated with API token\n" ) ;
57+ process . stdout . write ( ` Config saved to: ${ getConfigPath ( ) } \n` ) ;
58+ return ;
59+ }
6060
61- // OAuth Authorization Code flow
62- process . stdout . write ( "Starting OAuth authentication...\n\n" ) ;
61+ // OAuth Authorization Code flow
62+ process . stdout . write ( "Starting OAuth authentication...\n\n" ) ;
6363
64- try {
65- process . stdout . write ( "Opening browser for Sentry authorization...\n" ) ;
66- process . stdout . write (
67- `Waiting for authorization (timeout: ${ flags . timeout } s)...\n\n`
68- ) ;
64+ try {
65+ process . stdout . write ( "Opening browser for Sentry authorization...\n" ) ;
66+ process . stdout . write (
67+ `Waiting for authorization (timeout: ${ flags . timeout } s)...\n\n` ,
68+ ) ;
6969
70- // Perform the full OAuth flow
71- const tokenResponse = await performOAuthFlow ( ) ;
70+ // Perform the full OAuth flow
71+ const tokenResponse = await performOAuthFlow ( ) ;
7272
73- // Store the token
74- await completeOAuthFlow ( tokenResponse ) ;
73+ // Store the token
74+ await completeOAuthFlow ( tokenResponse ) ;
7575
76- process . stdout . write ( "\n✓ Authentication successful!\n" ) ;
77- process . stdout . write ( ` Config saved to: ${ getConfigPath ( ) } \n` ) ;
76+ process . stdout . write ( "\n✓ Authentication successful!\n" ) ;
77+ process . stdout . write ( ` Config saved to: ${ getConfigPath ( ) } \n` ) ;
7878
79- if ( tokenResponse . expires_in ) {
80- const hours = Math . round ( tokenResponse . expires_in / 3600 ) ;
81- process . stdout . write ( ` Token expires in: ${ hours } hours\n` ) ;
82- }
83- } catch ( error ) {
84- const message = error instanceof Error ? error . message : String ( error ) ;
85- process . stderr . write ( `\n✗ Authentication failed: ${ message } \n` ) ;
86- process . exitCode = 1 ;
87- }
88- } ,
79+ if ( tokenResponse . expires_in ) {
80+ const hours = Math . round ( tokenResponse . expires_in / 3600 ) ;
81+ process . stdout . write ( ` Token expires in: ${ hours } hours\n` ) ;
82+ }
83+ } catch ( error ) {
84+ const message = error instanceof Error ? error . message : String ( error ) ;
85+ process . stderr . write ( `\n✗ Authentication failed: ${ message } \n` ) ;
86+ process . exitCode = 1 ;
87+ }
88+ } ,
8989} ) ;
0 commit comments