Documentation
¶
Overview ¶
Package session implements a server-side session management strategy for managing user sessions.
The implementation uses a PostgreSQL database to store session data.
Index ¶
Constants ¶
View Source
const ( DefaultCookieName = "usid" DefaultExpiresIn = time.Hour * 12 )
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New[U, S any]( pool *pgxpool.Pool, config *Config[U, S], ) shieldsession.Authenticator[U, S]
New creates a new session authenticator.
The session authenticator uses a DB to store sessions and a cookie to store the session ID.
func WithHooker ¶
WithHooker sets a session hooker for a given config.
Types ¶
type Config ¶
type Hooker ¶
type Hooker[U, S any] interface { OnSessionIssue( context.Context, shield.User[U], shieldsession.Session[S], pgx.Tx, ) (shieldsession.Session[S], error) // OnSessionAuthenticate allows to hook into the session authentication process. OnSessionAuthenticate( context.Context, shieldsession.Session[S], pgx.Tx, ) (shieldsession.Session[S], error) // OnLogout allows to hook into the session logout process. OnLogout( ctx context.Context, userID, sessionID typeid.TypeID, tx pgx.Tx, ) error // OnExpireSessions allows to hook into session expiration process. OnExpireSessions( ctx context.Context, userID, sessionID typeid.TypeID, ) error }
type LogoutHandler ¶
type LogoutHandler[U, S any] struct { // contains filtered or unexported fields }
LogoutHandler is a handler that logs out the user and deletes the session.
func NewLogoutHandler ¶
func NewLogoutHandler[U, S any]( pool *pgxpool.Pool, config *Config[U, S], ) *LogoutHandler[U, S]
func (*LogoutHandler[U, S]) Logout ¶
func (h *LogoutHandler[U, S]) Logout( w http.ResponseWriter, r *http.Request, ) error
Logout logs out the user and deletes the session.
Click to show internal directories.
Click to hide internal directories.