Private
Public Access
fix: cambiado el jwt a una envvar
This commit is contained in:
1 parent
7e314e7730
commit
a137bf7ec8
2 files changed
+15
-3
No files matched your search
+14
-2
@@ -1,13 +1,25 @@
|
||||
package jwtutils
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"sync"
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
var JWTSecret = os.GetEnv("JWTSecret")
|
||||
var (
|
||||
JWTSecret []byte
|
||||
once sync.Once
|
||||
)
|
||||
|
||||
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 {
|
||||
return nil, jwt.ErrSignatureInvalid
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { setCurrentUser } from './user';
|
||||
async function handleResponse<T>(response: Response): Promise<T> {
|
||||
if (!response.ok) {
|
||||
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();
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user