Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LoginRequired ¶
func LoginRequired[T any](secretKey string, userLoader UserLoader[T]) gora.MiddlewareFunc
LoginRequired when called with secretKey and userLoader creates a jwt middleware that automatically extracts jwt from the request header, verifies it fetches the user using the userLoader function and attaches it to the context with the key "user". You can access the user downstream from the context and cast it Usage:
secretKey := os.Getenv("SECRET_KEY") func userLoader(id uint) (models.User, error){ return repo.FetchUser(id) } AuthMiddleware := LoginRequired(secretKey, userLoader) r := gora.Default() r.Use(AuthMiddleware)
Types ¶
type UserLoader ¶
UserLoader function loads user from the database given the id. Returns the user and an error if user can not be loaded or user is not active.
Click to show internal directories.
Click to hide internal directories.