add tests

This commit is contained in:
Fran Jurmanović
2025-07-07 01:40:19 +02:00
parent 07407e4db1
commit 44acb170a7
22 changed files with 6477 additions and 28 deletions

View File

@@ -65,6 +65,19 @@ func GenerateToken(user *model.User) (string, error) {
return token.SignedString(SecretKey)
}
func GenerateTokenWithExpiry(user *model.User, expiry time.Time) (string, error) {
expirationTime := expiry
claims := &Claims{
UserID: user.ID.String(),
RegisteredClaims: jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(expirationTime),
},
}
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
return token.SignedString(SecretKey)
}
// ValidateToken validates a JWT and returns the claims if the token is valid.
func ValidateToken(tokenString string) (*Claims, error) {
claims := &Claims{}