Properly reset login in progress flag after google login

This commit is contained in:
Tulir Asokan 2024-02-26 15:32:49 +02:00
parent 8eed8382cb
commit 7db7fdf20b
2 changed files with 13 additions and 4 deletions

View file

@ -426,6 +426,14 @@ func (prov *ProvisioningAPI) Login(w http.ResponseWriter, r *http.Request) {
}) })
return return
} }
if errors.Is(err, ErrLoginInProgress) && ch == nil {
log.Err(err).Msg("Tried to start QR login while non-QR login is in progress")
jsonResponse(w, http.StatusBadRequest, Error{
Error: "Non-QR login already in progress",
ErrCode: "unknown",
})
return
}
var item, prevItem qrChannelItem var item, prevItem qrChannelItem
var hasItem bool var hasItem bool

View file

@ -521,11 +521,14 @@ func (user *User) LoginGoogle(cookies map[string]string, emojiCallback func(stri
} else if !user.loginInProgress.CompareAndSwap(false, true) { } else if !user.loginInProgress.CompareAndSwap(false, true) {
return ErrLoginInProgress return ErrLoginInProgress
} }
defer user.loginInProgress.Store(false)
if user.Client != nil { if user.Client != nil {
user.unlockedDeleteConnection() user.unlockedDeleteConnection()
} }
pairSuccessChan := make(chan struct{}) user.pairSuccessChan = make(chan struct{})
user.pairSuccessChan = pairSuccessChan defer func() {
user.pairSuccessChan = nil
}()
authData := libgm.NewAuthData() authData := libgm.NewAuthData()
authData.Cookies = cookies authData.Cookies = cookies
user.createClient(authData) user.createClient(authData)
@ -533,8 +536,6 @@ func (user *User) LoginGoogle(cookies map[string]string, emojiCallback func(stri
err := user.Client.DoGaiaPairing(emojiCallback) err := user.Client.DoGaiaPairing(emojiCallback)
if err != nil { if err != nil {
user.unlockedDeleteConnection() user.unlockedDeleteConnection()
user.pairSuccessChan = nil
user.loginInProgress.Store(false)
return err return err
} }
return nil return nil