fix: implement token invalidation on password change

This commit is contained in:
Junming Chen
2025-12-29 17:18:17 -05:00
parent c01db6b180
commit 19d0ee130d
5 changed files with 32 additions and 6 deletions

View File

@@ -198,6 +198,7 @@ type userModel struct {
Concurrency int `gorm:"default:5;not null"`
Status string `gorm:"size:20;default:active;not null"`
AllowedGroups pq.Int64Array `gorm:"type:bigint[]"`
TokenVersion int64 `gorm:"default:0;not null"` // Incremented on password change
CreatedAt time.Time `gorm:"not null"`
UpdatedAt time.Time `gorm:"not null"`
DeletedAt gorm.DeletedAt `gorm:"index"`
@@ -221,6 +222,7 @@ func userModelToService(m *userModel) *service.User {
Concurrency: m.Concurrency,
Status: m.Status,
AllowedGroups: []int64(m.AllowedGroups),
TokenVersion: m.TokenVersion,
CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt,
}
@@ -242,6 +244,7 @@ func userModelFromService(u *service.User) *userModel {
Concurrency: u.Concurrency,
Status: u.Status,
AllowedGroups: pq.Int64Array(u.AllowedGroups),
TokenVersion: u.TokenVersion,
CreatedAt: u.CreatedAt,
UpdatedAt: u.UpdatedAt,
}
@@ -252,6 +255,7 @@ func applyUserModelToService(dst *service.User, src *userModel) {
return
}
dst.ID = src.ID
dst.TokenVersion = src.TokenVersion
dst.CreatedAt = src.CreatedAt
dst.UpdatedAt = src.UpdatedAt
}