Fix /google_login/wait provisioning API and add some logs

This commit is contained in:
Tulir Asokan 2024-02-23 22:07:50 +02:00
parent c806258b82
commit fec15f4bc8
2 changed files with 7 additions and 4 deletions

View file

@ -356,10 +356,6 @@ func (prov *ProvisioningAPI) GoogleLoginWait(w http.ResponseWriter, r *http.Requ
log := prov.zlog.With().Str("user_id", user.MXID.String()).Str("endpoint", "login").Logger()
if user.IsLoggedIn() {
jsonResponse(w, http.StatusOK, LoginResponse{Status: "success", ErrCode: "already logged in"})
return
}
err := user.AsyncLoginGoogleWait()
if err != nil {
log.Err(err).Msg("Failed to start login")

View file

@ -478,6 +478,7 @@ func (user *User) AsyncLoginGoogleStart(cookies map[string]string) (outEmoji str
var initialWait sync.WaitGroup
initialWait.Add(1)
callback := func(emoji string) {
user.zlog.Info().Msg("Async google login got emoji")
callbackDone = true
outEmoji = emoji
initialWait.Done()
@ -485,11 +486,17 @@ func (user *User) AsyncLoginGoogleStart(cookies map[string]string) (outEmoji str
go func() {
err := user.LoginGoogle(cookies, callback)
if !callbackDone {
user.zlog.Err(err).Msg("Async google login failed before callback")
initialWait.Done()
outErr = err
close(errChan)
user.googleAsyncPairErrChan.Store(nil)
} else {
if err != nil {
user.zlog.Err(err).Msg("Async google login failed after callback")
} else {
user.zlog.Info().Msg("Async google login succeeded")
}
errChan <- err
}
}()