Feature Description
I believe that all contrib middlewares that use the Fiber Context and allow the consumer to configure a custom context key must define the key to be of type interface{}.
Rationale
Using custom types for context keys is encouraged and common practice, both when using the standard Go context.Context and the Fiber fiber.Ctx.Locals function (see Fiber docs example on using Locals).
However, some contrib middlewares that rely on Fiber Context use a string key, forcing the consumer to go against standard practice.
Affected Middlewares
To my understanding, only the JWT and Paseto middlewares would require this change.
Contribution
I'm more than happy to make a PR for this if we agree on this change. 😃
Additional Context (optional)
No response
Code Snippet (optional)
package main
import (
jwtware "github.com/gofiber/contrib/jwt"
"github.com/gofiber/fiber/v2"
"github.com/golang-jwt/jwt/v5"
)
type customCtxKeyType struct{}
var ctxKeyUser = customCtxKeyType{}
func main() {
app := fiber.New()
app.Use(jwtware.New(jwtware.Config{
ContextKey: ctxKeyUser // <-- Error: Cannot use 'ctxKeyUser' (type customCtxKeyType) as the type string
}))
app.Get("/foo", func(c *fiber.Ctx) error {
userToken := c.Locals(ctxKeyUser).(*jwt.Token) // <-- OK
})
}
Checklist:
Feature Description
I believe that all contrib middlewares that use the Fiber Context and allow the consumer to configure a custom context key must define the key to be of type
interface{}.Rationale
Using custom types for context keys is encouraged and common practice, both when using the standard Go
context.Contextand the Fiberfiber.Ctx.Localsfunction (see Fiber docs example on using Locals).However, some contrib middlewares that rely on Fiber Context use a
stringkey, forcing the consumer to go against standard practice.Affected Middlewares
To my understanding, only the JWT and Paseto middlewares would require this change.
Contribution
I'm more than happy to make a PR for this if we agree on this change. 😃
Additional Context (optional)
No response
Code Snippet (optional)
Checklist: