sessionext

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2026 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package sessionext tells the web app when the current browser session will end and lets the person extend it, so the app can warn before an idle timeout instead of losing unsaved work.

A session ends at the earlier of its idle deadline (last activity plus the instance's idle timeout) and its absolute lifetime. Extending restarts the idle clock; the lifetime never moves, so an instance's policy can't be bypassed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(h huma.API, s *Service)

Register adds the session timing operations.

Types

type Service

type Service struct {
	Pool  *pgxpool.Pool
	Q     store.Querier
	Audit *audit.Logger
	// Policy returns the instance authentication policy (the idle timeout).
	Policy func(context.Context) (api.Policy, error)
	Now    func() time.Time
}

Service reads and extends the caller's session.

func (*Service) Extend

func (s *Service) Extend(ctx context.Context) (SessionTiming, error)

Extend restarts the idle clock of the caller's session. The change and its audit entry commit together.

func (*Service) Timing

func (s *Service) Timing(ctx context.Context) (SessionTiming, error)

Timing returns when the caller's session ends.

type SessionTiming

type SessionTiming struct {
	SignedInAt time.Time `json:"signedInAt" doc:"When this session was created"`
	LastSeenAt time.Time `json:"lastSeenAt" doc:"Last activity the server recorded; the idle clock runs from here"`
	// IdleTimeoutSeconds is 0 when the instance has no idle timeout.
	IdleTimeoutSeconds int64      `json:"idleTimeoutSeconds" doc:"The instance's idle timeout, in seconds"`
	IdleExpiresAt      *time.Time `json:"idleExpiresAt,omitempty" doc:"When the session ends without further activity"`
	ExpiresAt          time.Time  `json:"expiresAt" doc:"The session's absolute lifetime; extending never moves it"`
	EndsAt             time.Time  `json:"endsAt" doc:"The earlier of idleExpiresAt and expiresAt"`
	EndsBy             string     `json:"endsBy" enum:"idle,lifetime" doc:"Which limit ends the session first"`
	Extendable         bool       `json:"extendable" doc:"Whether extending now would end the session later"`
	ExtendsTo          *time.Time `json:"extendsTo,omitempty" doc:"When the session would end after extending now"`
	ServerTime         time.Time  `json:"serverTime" doc:"The server's clock, to correct for skew in the browser"`
}

SessionTiming says when the caller's session ends and what extending does.

Jump to

Keyboard shortcuts

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