login: allow retrying phone codes and 2fa passwords (#131)

This commit is contained in:
Tulir Asokan
2026-02-10 16:49:49 +02:00
committed by GitHub
parent 4071502854
commit e597eace68
3 changed files with 51 additions and 22 deletions
+17 -5
View File
@@ -159,8 +159,22 @@ func (bl *baseLogin) makeClient(ctx context.Context, dispatcher *tg.UpdateDispat
}
var passwordLoginStep = &bridgev2.LoginStep{
Type: bridgev2.LoginStepTypeUserInput,
StepID: LoginStepIDPassword,
Type: bridgev2.LoginStepTypeUserInput,
StepID: LoginStepIDPassword,
Instructions: "You have two-factor authentication enabled.",
UserInputParams: &bridgev2.LoginUserInputParams{
Fields: []bridgev2.LoginInputDataField{{
Type: bridgev2.LoginInputFieldTypePassword,
ID: LoginStepIDPassword,
Name: "Password",
}},
},
}
var passwordIncorrectLoginStep = &bridgev2.LoginStep{
Type: bridgev2.LoginStepTypeUserInput,
StepID: LoginStepIDPasswordIncorrect,
Instructions: "Incorrect password, please try again. Use the official Telegram app to reset your password if you've forgotten it.",
UserInputParams: &bridgev2.LoginUserInputParams{
Fields: []bridgev2.LoginInputDataField{{
Type: bridgev2.LoginInputFieldTypePassword,
@@ -179,9 +193,7 @@ func (bl *baseLogin) submitPassword(ctx context.Context, password, loginPhone st
authorization, err := bl.client.Auth().Password(ctx, password)
if err != nil {
if errors.Is(err, auth.ErrPasswordInvalid) {
// TODO re-prompt password instead of cancelling
bl.Cancel()
return nil, ErrInvalidPassword
return passwordIncorrectLoginStep, nil
}
bl.Cancel()
return nil, fmt.Errorf("failed to submit password: %w", err)