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