@@ -35,46 +35,32 @@ func (l *loginProvider) Login(ctx context.Context) (string, error) {
3535 }
3636
3737 authURL := fmt .Sprintf ("%s/auth/request/%s" , getWebAppURL (), authReq .ID )
38- output .EmitInfo (l .sink , fmt .Sprintf ("Visit: %s" , authURL ))
39- output .EmitInfo (l .sink , fmt .Sprintf ("Verification code: %s" , authReq .Code ))
4038
41- // Ask whether to open the browser; ENTER or Y accepts (default yes), N skips
42- browserCh := make (chan output.InputResponse , 1 )
43- output .EmitUserInputRequest (l .sink , output.UserInputRequestEvent {
44- Prompt : "Open browser now?" ,
45- Options : []output.InputOption {{Key : "y" , Label : "Y" }, {Key : "n" , Label : "n" }},
46- ResponseCh : browserCh ,
39+ output .EmitAuth (l .sink , output.AuthEvent {
40+ Preamble : "Welcome to lstk, a command-line interface for LocalStack" ,
41+ Code : authReq .Code ,
42+ URL : authURL ,
4743 })
44+ _ = browser .OpenURL (authURL )
4845
49- select {
50- case resp := <- browserCh :
51- if resp .Cancelled {
52- return "" , context .Canceled
53- }
54- if resp .SelectedKey != "n" {
55- if err := browser .OpenURL (authURL ); err != nil {
56- output .EmitWarning (l .sink , fmt .Sprintf ("Failed to open browser: %v" , err ))
57- }
58- }
59- case <- ctx .Done ():
60- return "" , ctx .Err ()
61- }
46+ output .EmitSpinnerStart (l .sink , "Waiting for authorization..." )
6247
63- // Wait for the user to complete authentication in the browser
64- enterCh := make (chan output.InputResponse , 1 )
48+ responseCh := make (chan output.InputResponse , 1 )
6549 output .EmitUserInputRequest (l .sink , output.UserInputRequestEvent {
66- Prompt : "Waiting for authentication " ,
67- Options : []output.InputOption {{Key : "enter " , Label : "Press ENTER when complete" }},
68- ResponseCh : enterCh ,
50+ Prompt : "Waiting for authorization... " ,
51+ Options : []output.InputOption {{Key : "any " , Label : "Press any key when complete" }},
52+ ResponseCh : responseCh ,
6953 })
7054
7155 select {
72- case resp := <- enterCh :
56+ case resp := <- responseCh :
57+ output .EmitSpinnerStop (l .sink )
7358 if resp .Cancelled {
7459 return "" , context .Canceled
7560 }
7661 return l .completeAuth (ctx , authReq )
7762 case <- ctx .Done ():
63+ output .EmitSpinnerStop (l .sink )
7864 return "" , ctx .Err ()
7965 }
8066}
0 commit comments