From d7d18f128433d1e9ac7d0acbd36a4c5eef63254f Mon Sep 17 00:00:00 2001 From: Nikolai Papin Date: Mon, 4 Aug 2025 21:17:06 +0300 Subject: [PATCH] fix: corrected redis logic to prevent temporary lock-outs on failed database transactions; fix: ChangePassword transaction isolation; chore: highlighted issues --- backend/internal/services/auth.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/backend/internal/services/auth.go b/backend/internal/services/auth.go index 489faaa..ed840d0 100644 --- a/backend/internal/services/auth.go +++ b/backend/internal/services/auth.go @@ -348,6 +348,14 @@ func (a *authServiceImpl) RegistrationBegin(request models.RegistrationBeginRequ a.log.Error( "Failed to commit transaction", zap.Error(err)) + + redisErr := a.redis.Del(context.TODO(), fmt.Sprintf("email::%s::registration_in_progress", request.Email)) + if redisErr != nil { + a.log.Error( + "Failed to delete cooldown redis key while rolling back RegistrationBegin", + zap.Error(redisErr.Err())) + } + return false, errs.ErrServerError } @@ -808,6 +816,14 @@ func (a *authServiceImpl) PasswordResetBegin(request models.PasswordResetBeginRe a.log.Error( "Failed to commit transaction", zap.Error(err)) + + redisErr := a.redis.Del(context.TODO(), fmt.Sprintf("email::%s::reset_cooldown", request.Email)) + if redisErr != nil { + a.log.Error( + "Failed to delete cooldown redis key while rolling back PasswordResetBegin", + zap.Error(redisErr.Err())) + } + return false, errs.ErrServerError } @@ -904,6 +920,7 @@ func (a *authServiceImpl) PasswordResetComplete(request models.PasswordResetComp } } + // FIXME: grab client info session, err = db.TXQueries.CreateSession(db.CTX, database.CreateSessionParams{ UserID: user.ID, Name: utils.NewPointer("First device"), @@ -947,6 +964,7 @@ func (a *authServiceImpl) PasswordResetComplete(request models.PasswordResetComp return &response, nil } +// XXX: Mechanism for loging out existing sessions currently does not exist func (a *authServiceImpl) ChangePassword(request models.ChangePasswordRequest, uinfo dto.ClientInfo) (bool, error) { var err error @@ -981,7 +999,7 @@ func (a *authServiceImpl) ChangePassword(request models.ChangePasswordRequest, u return false, errs.ErrServerError } - err = db.TXlessQueries.UpdateLoginInformationByUsername(db.CTX, database.UpdateLoginInformationByUsernameParams{ + err = db.TXQueries.UpdateLoginInformationByUsername(db.CTX, database.UpdateLoginInformationByUsernameParams{ Username: uinfo.Username, PasswordHash: newPasswordHash, }); if err != nil { -- 2.49.1