Skip to content

Commit

Permalink
client: fix detection of bad credentials on connect
Browse files Browse the repository at this point in the history
Signed-off-by: Sumner Evans <[email protected]>
  • Loading branch information
sumnerevans committed Dec 5, 2024
1 parent 80f17d5 commit 4d33af7
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions pkg/connector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ import (
"go.mau.fi/mautrix-telegram/pkg/connector/util"
)

var ErrNoAuthKey = errors.New("user does not have auth key")

type TelegramClient struct {
main *TelegramConnector
ScopedStore *store.ScopedStore
Expand Down Expand Up @@ -395,7 +397,7 @@ func (t *TelegramClient) onDead() {
}

func (t *TelegramClient) sendBadCredentialsOrUnknownError(err error) {
if auth.IsUnauthorized(err) {
if auth.IsUnauthorized(err) || errors.Is(err, ErrNoAuthKey) {
t.userLogin.BridgeState.Send(status.BridgeState{
StateEvent: status.StateBadCredentials,
Error: "tg-no-auth",
Expand Down Expand Up @@ -453,7 +455,7 @@ func (t *TelegramClient) onAuthError(ctx context.Context, err error) {

func (t *TelegramClient) Connect(ctx context.Context) {
if !t.userLogin.Metadata.(*UserLoginMetadata).Session.HasAuthKey() {
t.sendBadCredentialsOrUnknownError(errors.New("user does not have an auth key"))
t.sendBadCredentialsOrUnknownError(ErrNoAuthKey)
return
}

Expand Down

0 comments on commit 4d33af7

Please sign in to comment.