fix(auth): avoid blocking oauth callback wait on prompt

This commit is contained in:
hkfires
2026-03-20 11:48:30 +08:00
parent 2bd646ad70
commit cccb77b552
5 changed files with 108 additions and 23 deletions

View File

@@ -109,6 +109,9 @@ func (a *IFlowAuthenticator) Login(ctx context.Context, cfg *config.Config, opts
defer manualPromptTimer.Stop()
}
var manualInputCh <-chan string
var manualInputErrCh <-chan error
waitForCallback:
for {
select {
@@ -128,10 +131,22 @@ waitForCallback:
return nil, fmt.Errorf("iflow auth: callback wait failed: %w", err)
default:
}
input, errPrompt := opts.Prompt("Paste the iFlow callback URL (or press Enter to keep waiting): ")
if errPrompt != nil {
return nil, errPrompt
}
inputCh := make(chan string, 1)
inputErrCh := make(chan error, 1)
go func() {
input, errPrompt := opts.Prompt("Paste the iFlow callback URL (or press Enter to keep waiting): ")
if errPrompt != nil {
inputErrCh <- errPrompt
return
}
inputCh <- input
}()
manualInputCh = inputCh
manualInputErrCh = inputErrCh
continue
case input := <-manualInputCh:
manualInputCh = nil
manualInputErrCh = nil
parsed, errParse := misc.ParseOAuthCallback(input)
if errParse != nil {
return nil, errParse
@@ -145,6 +160,8 @@ waitForCallback:
Error: parsed.Error,
}
break waitForCallback
case errManual := <-manualInputErrCh:
return nil, errManual
}
}
if result.Error != "" {