diff --git a/provisioning.go b/provisioning.go index 85c1c62..f8ac118 100644 --- a/provisioning.go +++ b/provisioning.go @@ -426,6 +426,14 @@ func (prov *ProvisioningAPI) Login(w http.ResponseWriter, r *http.Request) { }) 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 hasItem bool diff --git a/user.go b/user.go index 4080f7b..e72737d 100644 --- a/user.go +++ b/user.go @@ -521,11 +521,14 @@ func (user *User) LoginGoogle(cookies map[string]string, emojiCallback func(stri } else if !user.loginInProgress.CompareAndSwap(false, true) { return ErrLoginInProgress } + defer user.loginInProgress.Store(false) if user.Client != nil { user.unlockedDeleteConnection() } - pairSuccessChan := make(chan struct{}) - user.pairSuccessChan = pairSuccessChan + user.pairSuccessChan = make(chan struct{}) + defer func() { + user.pairSuccessChan = nil + }() authData := libgm.NewAuthData() authData.Cookies = cookies user.createClient(authData) @@ -533,8 +536,6 @@ func (user *User) LoginGoogle(cookies map[string]string, emojiCallback func(stri err := user.Client.DoGaiaPairing(emojiCallback) if err != nil { user.unlockedDeleteConnection() - user.pairSuccessChan = nil - user.loginInProgress.Store(false) return err } return nil