Documentation
¶
Index ¶
Constants ¶
View Source
const ( DefaultContextKey = "secret-user-data" DefaultAuthContextKey = "auth-token" )
Variables ¶
View Source
var ConfigDefault = Config{ Next: nil, Forbidden: nil, AuthContextKey: DefaultAuthContextKey, NamespaceContextKey: DefaultContextKey, CacheStorage: memory.New(), }
ConfigDefault is the default config
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Next defines a function to skip this middleware when returned true.
//
// Optional. Default: nil
Next func(context *fiber.Ctx) bool
// NamespaceChecker defines a function that checks user and returns its ID, in case user not found, return 0
//
// Required. Default: nil
NamespaceChecker TokenChecker
// CheckerError defines the response body for unauthorized responses.
// By default, it will return with a 401 CheckerError
//
// Optional. Default: nil
CheckerError fiber.Handler
// Forbidden defines the response body for unauthorized responses.
// By default it will return with a 403 Forbidden
//
// Optional. Default: nil
Forbidden fiber.Handler
// AuthContextKey is the key to look out the auth name in Locals
//
// Optional. Default: "auth-token"
AuthContextKey string
// NamespaceContextKey is the key to store the userID in Locals
//
// Optional. Default: "secret-user-id"
NamespaceContextKey string
// CacheStorage is the storage used to store users in cache, to preventing searching them multiple times
//
// Optional. Default: memory
CacheStorage fiber.Storage
}
Config defines all configs needed by the middleware
type TokenChecker ¶
type TokenChecker func(authToken string) (*dtos.CustomerDTO, error)
Config defines the config for middleware.
Click to show internal directories.
Click to hide internal directories.