1

I used golang jwt middleware.

e.Use(middleware.JWTWithConfig(middleware.JWTConfig{
  SigningKey:  []byte(os.Getenv("Signing_Key")),
  TokenLookup: "header:x-auth-token",       
}))

It waits token for all functions but I don't want to use this middleware for login function. How to prevent this?

Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103
oakkose
  • 353
  • 3
  • 13

2 Answers2

10

There is a skipper function. You can use it to check which route to skip.

JWTConfig struct {
  // Skipper defines a function to skip middleware.
  Skipper Skipper
  ... 
}

Check an example:

e.Use(middleware.JWTWithConfig(middleware.JWTConfig{
    SigningKey:  []byte(os.Getenv("Signing_Key")),
    TokenLookup: "header:x-auth-token",
    Skipper: func(c echo.Context) bool {
       // Skip middleware if path is equal 'login'
       if c.Request().URL.Path == "/login" {
         return true
       }
       return false
    },
}))
 
Roman Kiselenko
  • 43,210
  • 9
  • 91
  • 103
1

It could be something like this

e.Use(middleware.JWTWithConfig(middleware.JWTConfig{
    SigningKey:  []byte(os.Getenv("Signing_Key")),
    TokenLookup: "header:x-auth-token",
    Skipper: func(c echo.Context) bool {
       return c.Request().URL.Path == "/login"
    }
}))
otaxhu
  • 11
  • 3