我使用了 golang jwt 中間件。e.Use(middleware.JWTWithConfig(middleware.JWTConfig{ SigningKey: []byte(os.Getenv("Signing_Key")), TokenLookup: "header:x-auth-token", }))它等待所有功能的令牌,但我不想將此中間件用于登錄功能。如何防止這種情況?
1 回答

慕村9548890
TA貢獻1884條經驗 獲得超4個贊
有一個skipper
功能。您可以使用它來檢查要跳過的路線。
JWTConfig struct {
// Skipper defines a function to skip middleware.
Skipper Skipper
...
}
檢查一個例子:
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
},
}))
- 1 回答
- 0 關注
- 99 瀏覽
添加回答
舉報
0/150
提交
取消