From 2b8c74a0f1fcebcb8ef216f8f9a4973b5655bc28 Mon Sep 17 00:00:00 2001 From: yml2213 Date: Thu, 10 Sep 2026 13:26:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(auth):=20=E7=94=A8=E6=88=B7=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E7=89=88=E6=9C=AC=E9=BB=98=E8=AE=A4=E5=80=BC=E5=AF=B9?= =?UTF-8?q?=E9=BD=90=20main=EF=BC=8C=E6=94=B6=E6=95=9B=20dev=20=E8=A1=80?= =?UTF-8?q?=E8=84=89=E7=9A=84=201=20=E5=81=8F=E5=B7=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit token_version 由 c91423a 引入时,model tag 与迁移 000052 一致都是 0; TokenVersion 的显式赋值 1 只存在于 dev 分支的 85332df,main 上从未有过。 本次把用户侧(users 表)统一收敛到 0,管理员侧(admin_users)保持不动。 - model/user.go:TokenVersion 的 gorm tag 由 default:1 改为 default:0 - auth/repository.go:FindOrCreateByPhone / RegisterWithPassword 移除 显式 TokenVersion: 1,改由列默认值决定 行为收敛:此前 listing/mutation.go 的建号路径完全不显式赋值, 落库值取决于 DB 列默认值(本机 1 / 迁移定义 0),是真实的行为漂移来源; 现在三条建号路径结果一致,均为 0。 判定依据:引入该字段的提交是否自洽 + 该值是否在 main 上, 不以本机库的实际列定义为准(本地曾被手工改成 1)。 --- backend/internal/model/user.go | 5 +++-- backend/internal/modules/auth/repository.go | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/backend/internal/model/user.go b/backend/internal/model/user.go index 33f8095..2726695 100644 --- a/backend/internal/model/user.go +++ b/backend/internal/model/user.go @@ -15,8 +15,9 @@ type User struct { RenterGrowthPoints int64 `gorm:"not null;default:0;index:idx_users_renter_growth_level,priority:2" json:"renter_growth_points"` RenterGrowthLevel string `gorm:"size:32;not null;default:'normal';index:idx_users_renter_growth_level,priority:1" json:"renter_growth_level"` Status string `gorm:"size:32;not null;default:'active'" json:"status"` - // 会话版本:默认与 users.token_version 列默认值保持一致,递增后旧令牌失效。 - TokenVersion int64 `gorm:"not null;default:1" json:"-"` + // 会话版本:递增后该用户已签发的全部令牌立即失效。 + // 默认值对齐迁移 000052 的 users.token_version DEFAULT 0。 + TokenVersion int64 `gorm:"not null;default:0" json:"-"` // 注册归因:注册时由前端携带的推广短码。 RegisterTrackCode string `gorm:"size:64;index:idx_users_register_track_code" json:"register_track_code,omitempty"` LastLoginAt *time.Time `json:"last_login_at"` diff --git a/backend/internal/modules/auth/repository.go b/backend/internal/modules/auth/repository.go index a61f425..4cebfec 100644 --- a/backend/internal/modules/auth/repository.go +++ b/backend/internal/modules/auth/repository.go @@ -83,7 +83,6 @@ func (r *UserRepository) FindOrCreateByPhone(ctx context.Context, phone string, CreditScore: 100, Status: "active", RegisterTrackCode: code, - TokenVersion: 1, LastLoginAt: &now, } @@ -138,7 +137,6 @@ func (r *UserRepository) RegisterWithPassword(ctx context.Context, phone string, CreditScore: 100, Status: "active", RegisterTrackCode: code, - TokenVersion: 1, LastLoginAt: &now, }