From 772c12f8218082cf2b88dba1967e170620b6e1c4 Mon Sep 17 00:00:00 2001 From: shanshanzhong Date: Wed, 11 Mar 2026 10:07:14 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=B3=A8=E9=94=80=E5=90=8E=20device=20l?= =?UTF-8?q?ogin=20=E8=A1=A5=E5=9B=9E=E8=A2=AB=E5=88=A0=E9=99=A4=E7=9A=84?= =?UTF-8?q?=20device=20auth=5Fmethod=EF=BC=8C=E4=BF=AE=E5=A4=8D=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E6=8C=89=E9=92=AE=E6=98=BE=E7=A4=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: claude-flow --- internal/logic/auth/deviceLoginLogic.go | 27 +++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/internal/logic/auth/deviceLoginLogic.go b/internal/logic/auth/deviceLoginLogic.go index 2d71fd5..8093ec1 100644 --- a/internal/logic/auth/deviceLoginLogic.go +++ b/internal/logic/auth/deviceLoginLogic.go @@ -96,6 +96,33 @@ func (l *DeviceLoginLogic) DeviceLogin(req *types.DeviceLoginRequest) (resp *typ ) return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "query user failed: %v", err.Error()) } + + // 注销后 device auth_method 被删除,重新登录时需要补回 + hasDeviceAuth := false + for _, am := range userInfo.AuthMethods { + if am.AuthType == "device" && am.AuthIdentifier == req.Identifier { + hasDeviceAuth = true + break + } + } + if !hasDeviceAuth { + authMethod := &user.AuthMethods{ + UserId: userInfo.Id, + AuthType: "device", + AuthIdentifier: req.Identifier, + Verified: true, + } + if createErr := l.svcCtx.DB.Create(authMethod).Error; createErr != nil { + l.Errorw("re-create device auth method failed", + logger.Field("user_id", userInfo.Id), + logger.Field("identifier", req.Identifier), + logger.Field("error", createErr.Error()), + ) + } else { + // 清缓存让后续 FindOne 返回最新 AuthMethods + _ = l.svcCtx.UserModel.ClearUserCache(l.ctx, userInfo) + } + } } // Generate session id