Update
This commit is contained in:
parent
7adf3b9512
commit
380fe41d1a
@ -4,20 +4,20 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
jwtMiddleware "github.com/gofiber/jwt/v2"
|
jwt "github.com/gofiber/jwt/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// JWTProtected func for specify routes group with JWT authentication.
|
// JWTProtected func for specify routes group with JWT authentication.
|
||||||
// See: https://github.com/gofiber/jwt
|
// See: https://github.com/gofiber/jwt
|
||||||
func JWTProtected() func(*fiber.Ctx) error {
|
func JWTProtected() func(*fiber.Ctx) error {
|
||||||
// Create config for JWT authentication middleware.
|
// Create config for JWT authentication middleware.
|
||||||
config := jwtMiddleware.Config{
|
config := jwt.Config{
|
||||||
SigningKey: []byte(os.Getenv("JWT_SECRET_KEY")),
|
SigningKey: []byte(os.Getenv("JWT_SECRET_KEY")),
|
||||||
ContextKey: "jwt", // used in private routes
|
ContextKey: "jwt", // used in private routes
|
||||||
ErrorHandler: jwtError,
|
ErrorHandler: jwtError,
|
||||||
}
|
}
|
||||||
|
|
||||||
return jwtMiddleware.New(config)
|
return jwt.New(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func jwtError(c *fiber.Ctx, err error) error {
|
func jwtError(c *fiber.Ctx, err error) error {
|
||||||
|
Loading…
Reference in New Issue
Block a user