code refactoring, fix jwt
This commit is contained in:
@@ -8,10 +8,7 @@ import (
|
||||
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"github.com/marcopeocchi/yt-dlp-web-ui/server/config"
|
||||
)
|
||||
|
||||
const (
|
||||
TOKEN_COOKIE_NAME = "jwt"
|
||||
"github.com/marcopeocchi/yt-dlp-web-ui/server/utils"
|
||||
)
|
||||
|
||||
func Authenticated(next http.Handler) http.Handler {
|
||||
@@ -21,7 +18,7 @@ func Authenticated(next http.Handler) http.Handler {
|
||||
return
|
||||
}
|
||||
|
||||
cookie, err := r.Cookie(TOKEN_COOKIE_NAME)
|
||||
cookie, err := r.Cookie(utils.TOKEN_COOKIE_NAME)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, "invalid token", http.StatusBadRequest)
|
||||
@@ -37,7 +34,7 @@ func Authenticated(next http.Handler) http.Handler {
|
||||
if _, ok := t.Method.(*jwt.SigningMethodHMAC); !ok {
|
||||
return nil, fmt.Errorf("unexpected signing method: %v", t.Header["alg"])
|
||||
}
|
||||
return []byte(os.Getenv("JWTSECRET")), nil
|
||||
return []byte(os.Getenv("JWT_SECRET")), nil
|
||||
})
|
||||
|
||||
if claims, ok := token.Claims.(jwt.MapClaims); ok && token.Valid {
|
||||
|
||||
Reference in New Issue
Block a user