From 432ed2d5aa75ec723706bd0f6b3f873796b52dd8 Mon Sep 17 00:00:00 2001 From: Jared Kling Date: Sun, 30 Nov 2025 08:10:54 -0600 Subject: [PATCH] Use subject claim for user id --- internal/auth/manager.go | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/internal/auth/manager.go b/internal/auth/manager.go index 982e44c..89d4ec0 100644 --- a/internal/auth/manager.go +++ b/internal/auth/manager.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "os" + "strconv" "time" "github.com/golang-jwt/jwt/v5" @@ -18,8 +19,7 @@ var ( // Claims represents the JWT claims structure type Claims struct { - UserID int64 `json:"user_id"` - Email string `json:"email"` + Email string `json:"email"` jwt.RegisteredClaims } @@ -38,9 +38,9 @@ func NewJWTManager(secretKey string, tokenDuration time.Duration) *JWTManager { // GenerateToken creates a new JWT token for a user func (m *JWTManager) GenerateToken(userID int64, email string) (string, error) { claims := Claims{ - UserID: userID, - Email: email, + Email: email, RegisteredClaims: jwt.RegisteredClaims{ + Subject: strconv.FormatInt(userID, 10), ExpiresAt: jwt.NewNumericDate(time.Now().Add(m.tokenDuration)), IssuedAt: jwt.NewNumericDate(time.Now()), NotBefore: jwt.NewNumericDate(time.Now()), @@ -97,5 +97,9 @@ func (m *JWTManager) RefreshToken(tokenString string) (string, error) { return "", err } - return m.GenerateToken(claims.UserID, claims.Email) + userId, err := strconv.ParseInt(claims.Subject, 10, 64) + if err != nil { + return "", err + } + return m.GenerateToken(userId, claims.Email) }