Documentation
¶
Overview ¶
Package acctctx provides type-safe access to account-related values stored in the context.
Index ¶
- func Account(ctx context.Context) *accounts.Account
- func ReplaceSessionData(ctx context.Context, p any) error
- func ResetSession(ctx context.Context, ssnID string, ssnData json.RawMessage)
- func Session(ctx context.Context) (ssnID string, data json.RawMessage, dirty bool)
- func SessionID(ctx context.Context) string
- func WithAccount(ctx context.Context, acct *accounts.Account) context.Context
- func WithSession(ctx context.Context, ssnID string, ssnData json.RawMessage) context.Context
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReplaceSessionData ¶
ReplaceSessionData replaces the data associated with the current session with the JSON-marshaled version of p, and marks the session data as dirty. It always assumes that the data changed when this function is called.
func ResetSession ¶
func ResetSession(ctx context.Context, ssnID string, ssnData json.RawMessage)
ResetSession updates an existing context session in-place with the provided ssnID and ssnData, marking the data as unmodified. It should be used when the session id changes inside the handler wrapped by the Session middleware (e.g. after a login, going from anonymous to authenticated, or the reverse after a logout or a delete account).
As a special case, if ssnData is nil or empty slice, it will be stored as JSON "null".
func Session ¶
Session returns the current session id and its associated data, along with a boolean indicating if the data is dirty (if any changes were made since the call to WithSession or ResetSession).
func SessionID ¶
SessionID returns the session ID stored in the context or an empty string if there is none.
func WithAccount ¶
WithAccount returns a context that holds the specified account. Typically this is the currently authenticated account.
func WithSession ¶
WithSession returns a context that holds the specified session information. Unlike ResetSession, WithSession always stores a new session entry in the context. It should be used for the initial set of the session, typically called automatically by the Session middleware. An empty ssnID indicates that a new anonymous session should be created to store the data when the Session middleware exits.
As a special case, if ssnData is nil or empty slice, it will be stored as JSON "null".
Types ¶
This section is empty.