update refresh

This commit is contained in:
2026-07-06 12:58:27 +07:00
parent e4007eb15a
commit 57687d1d62
15 changed files with 483 additions and 66 deletions
+6 -4
View File
@@ -5,15 +5,16 @@ import (
"time"
"github.com/golang-jwt/jwt/v5"
"github.com/google/uuid"
)
type processor struct {
secret string
secret []byte
}
func NewProcessor(secret string) IProcessorJWT {
return &processor{
secret: secret,
secret: []byte(secret),
}
}
@@ -32,7 +33,7 @@ func (p *processor) GenerateAccessToken(userId int, userEmail string, userRoles
}
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
return token.SignedString([]byte(p.secret))
return token.SignedString(p.secret)
}
func (p *processor) GenerateRefreshToken(userId int) (string, error) {
@@ -44,11 +45,12 @@ func (p *processor) GenerateRefreshToken(userId int) (string, error) {
ExpiresAt: jwt.NewNumericDate(now.Add(7 * 24 * time.Hour)),
IssuedAt: jwt.NewNumericDate(now),
NotBefore: jwt.NewNumericDate(now),
ID: uuid.New().String(),
},
}
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
return token.SignedString([]byte(p.secret))
return token.SignedString(p.secret)
}
func (p *processor) GetClaims(token string) (*JWTClaims, error) {