session

package
v0.28.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoSession       = errors.New("no session")
	ErrDeletingSession = errors.New("error deleting session")
)

Functions

This section is empty.

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
}

type Service

type Service struct {
	Now func() time.Time
	// contains filtered or unexported fields
}

func NewService

func NewService(logger log.Logger, repo Repository, validity time.Duration) *Service

func (Service) Close

func (s Service) Close() error

func (Service) Create

func (s Service) Create(ctx context.Context, userID string) (*Session, error)

func (Service) Delete

func (s Service) Delete(ctx context.Context, sessionID uuid.UUID) error

func (Service) ExtractFromContext

func (s Service) ExtractFromContext(ctx context.Context) (*Session, error)

func (Service) InitSessions

func (s Service) InitSessions(ctx context.Context) error

InitSessions Initiates CronJob to delete expired sessions from the database

func (Service) Refresh

func (s Service) Refresh(ctx context.Context, sessionID uuid.UUID) error

Refresh extends validity of session

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

	Metadata metadata.Metadata
}

Session is created on successful authentication of users

func (Session) IsValid

func (s Session) IsValid(now time.Time) bool

Jump to

Keyboard shortcuts

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