Merge pull request 'correjido el tema del token hardcodeado' (#25) from jwt-envvar into dev

Reviewed-on: #25
This commit was merged in pull request #25.
This commit is contained in:
fede committed 2026-06-17 20:38:38 -03:00
commit ab88be0ba5
2 files changed
+15 -3

No files matched your search

+14 -2
View File
@@ -1,13 +1,25 @@
package jwtutils package jwtutils
import ( import (
"os"
"sync"
"github.com/golang-jwt/jwt/v5" "github.com/golang-jwt/jwt/v5"
"github.com/joho/godotenv"
) )
var JWTSecret = []byte("supersecretkey123456789") var (
JWTSecret []byte
once sync.Once
)
func ValidarJWT(tokenString string) (jwt.MapClaims, error) { func ValidarJWT(tokenString string) (jwt.MapClaims, error) {
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (interface{}, error) { once.Do(func() {
godotenv.Load()
JWTSecret = []byte(os.Getenv("JWTString"))
})
token, err := jwt.Parse(tokenString, func(token *jwt.Token) (any, error) {
if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok { if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
return nil, jwt.ErrSignatureInvalid return nil, jwt.ErrSignatureInvalid
} }
+1 -1
View File
@@ -6,7 +6,7 @@ import { setCurrentUser } from './user';
async function handleResponse<T>(response: Response): Promise<T> { async function handleResponse<T>(response: Response): Promise<T> {
if (!response.ok) { if (!response.ok) {
const error = await response.json().catch(() => ({ message: 'Error desconocido' })); const error = await response.json().catch(() => ({ message: 'Error desconocido' }));
throw new Error(error.message || 'Error en la petición'); throw new Error(error.error || 'Error en la petición');
} }
return response.json(); return response.json();
} }