Documentation
¶
Index ¶
- Variables
- func SetSessionMetadataInContext(ctx context.Context, metadata SessionMetadata) context.Context
- type Repository
- type Service
- func (s Service) Close() error
- func (s Service) Create(ctx context.Context, userID string, metadata SessionMetadata) (*Session, error)
- func (s Service) Delete(ctx context.Context, sessionID uuid.UUID) error
- func (s Service) ExtractFromContext(ctx context.Context) (*Session, error)
- func (s Service) Get(ctx context.Context, sessionID uuid.UUID) (*Session, error)
- func (s Service) GetByID(ctx context.Context, sessionID uuid.UUID) (*Session, error)
- func (s Service) InitSessions(ctx context.Context) error
- func (s Service) List(ctx context.Context, userID string) ([]*Session, error)
- func (s Service) Ping(ctx context.Context, sessionID uuid.UUID, metadata SessionMetadata) error
- func (s Service) Refresh(ctx context.Context, sessionID uuid.UUID) error
- type Session
- type SessionMetadata
Constants ¶
This section is empty.
Variables ¶
View Source
var ( ErrNoSession = errors.New("no session") ErrDeletingSession = errors.New("error deleting session") )
Functions ¶
func SetSessionMetadataInContext ¶ added in v0.76.0
func SetSessionMetadataInContext(ctx context.Context, metadata SessionMetadata) context.Context
SetSessionMetadataInContext sets session metadata in context It accepts a SessionMetadata struct but stores it as a map with the same structure to avoid layer violations in repositories
Types ¶
type Repository ¶
type Repository interface {
Set(ctx context.Context, session *Session) error
Get(ctx context.Context, id uuid.UUID) (*Session, error)
Delete(ctx context.Context, id uuid.UUID) error
DeleteExpiredSessions(ctx context.Context) error
UpdateValidity(ctx context.Context, id uuid.UUID, validity time.Duration) error
List(ctx context.Context, userID string) ([]*Session, error)
UpdateSessionMetadata(ctx context.Context, id uuid.UUID, metadata SessionMetadata, updatedAt time.Time) error
}
type Service ¶
func NewService ¶
func (Service) ExtractFromContext ¶
func (Service) InitSessions ¶
InitSessions Initiates CronJob to delete expired sessions from the database
type Session ¶
type Session struct {
ID uuid.UUID
// UserID is a unique identifier for logged in users
UserID string
// AuthenticatedAt is set when a user is successfully authn
AuthenticatedAt time.Time
// ExpiresAt is ideally now() + lifespan of session, e.g. 7 days
ExpiresAt time.Time
CreatedAt time.Time
UpdatedAt time.Time
DeletedAt *time.Time // Soft delete timestamp (nil = not deleted)
Metadata SessionMetadata
}
Session is created on successful authentication of users
Click to show internal directories.
Click to hide internal directories.