This commit is contained in:
Tomas Dvorak
2025-10-28 22:38:27 +01:00
parent 3d621e2187
commit 823fabee02
106 changed files with 9011 additions and 3930 deletions
+9 -1
View File
@@ -3,6 +3,7 @@ package utils
import (
"errors"
"os"
"strconv"
"strings"
"time"
@@ -20,7 +21,14 @@ type JWTClaims struct {
// GenerateJWT generates a new JWT token for the given user
func GenerateJWT(userID uint, email, role string) (string, error) {
expirationTime := time.Now().Add(24 * time.Hour)
// Respect configurable expiration via JWT_EXPIRATION_HOURS; default 24h
expHours := 24
if v := os.Getenv("JWT_EXPIRATION_HOURS"); v != "" {
if n, err := strconv.Atoi(v); err == nil && n > 0 && n <= 24*365 {
expHours = n
}
}
expirationTime := time.Now().Add(time.Duration(expHours) * time.Hour)
claims := &JWTClaims{
UserID: userID,