user

package
v0.0.0-...-608b5f9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 26, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLoginRequired = errors.New("login required")

ErrLoginRequired is returned with RequireLoginError middleware.

Functions

func GetSessionUser

func GetSessionUser(ctx context.Context) (*model.User, bool)

GetSessionUser will return the user bound to the session. If there's no active user bound, the return is nil, false.

func NewMiddleware

func NewMiddleware(opts ...MiddlewareOption) func(http.Handler) http.Handler

NewMiddleware will populate context for IsLoggedIn, GetSessionUser.

func NewModule

func NewModule() *service.UserModule

NewModule will return the user module.

func SetSessionUser

func SetSessionUser(ctx context.Context, u *model.User) context.Context

SetSessionUser is here to aid testing, for internal use.

func SigningKey

func SigningKey() string

Types

type Middleware

type Middleware struct {
	// contains filtered or unexported fields
}

Middleware requires a user login for the registered route. If an Authorize header is provided, it will decode the JWT and use the user_id claim to authenticate API requests.

How do you generate the JWT you ask? Good question. TBD.

func (*Middleware) ServeHTTP

func (m *Middleware) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP authenticates the request and passes it to the next handler.

type MiddlewareOption

type MiddlewareOption func(*Middleware)

MiddlewareOption configures the user authentication middleware.

func AuthCookie

func AuthCookie() MiddlewareOption

AuthCookie enables session-based authentication via a cookie.

func AuthHeader

func AuthHeader() MiddlewareOption

AuthHeader enables JWT-based authentication via the Authorization header.

func AuthQuery

func AuthQuery(paramName string) MiddlewareOption

AuthQuery enables JWT-based authentication via URL query parameter. Useful for headless browsers that can't set Authorization headers.

Directories

Path Synopsis
cmd
generate command
api
web

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL