sessions

package
v0.0.0-...-36ecd39 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SessionAuthLevelPrimary = 1
	SessionAuthLevelFull    = 2
)
View Source
const SessionCookieName = "session"

Variables

View Source
var ErrInvalidSession = errors.New("invalid session")

Functions

func GetSessionToken

func GetSessionToken(r *http.Request) string

func RequireSameOrigin

func RequireSameOrigin(allowedOrigin string) func(http.Handler) http.Handler

func VerifyRequestOrigin

func VerifyRequestOrigin(r *http.Request, allowedOrigin string) bool

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(cfg ClientConfig) (*Client, error)

func (*Client) ClearSessionCookie

func (c *Client) ClearSessionCookie(w http.ResponseWriter)

func (*Client) CreateSession

func (c *Client) CreateSession(ctx context.Context, userID string) (string, error)

func (*Client) CreateSessionWithAuthLevel

func (c *Client) CreateSessionWithAuthLevel(ctx context.Context, userID string, authLevel int) (string, error)

func (*Client) DeleteSession

func (c *Client) DeleteSession(ctx context.Context, sessionID string) error

func (*Client) DeleteUserSessions

func (c *Client) DeleteUserSessions(ctx context.Context, userID string) error

func (*Client) Logout

func (c *Client) Logout(ctx context.Context) (string, error)

func (*Client) LogoutHTTP

func (c *Client) LogoutHTTP(w http.ResponseWriter, r *http.Request) error

func (*Client) RequireFullSession

func (c *Client) RequireFullSession(next http.Handler) http.Handler

func (*Client) RequireSession

func (c *Client) RequireSession(next http.Handler) http.Handler

func (*Client) SessionMiddleware

func (c *Client) SessionMiddleware() func(http.Handler) http.Handler

func (*Client) SetSessionCookie

func (c *Client) SetSessionCookie(w http.ResponseWriter, token string)

func (*Client) UpgradeSessionToFull

func (c *Client) UpgradeSessionToFull(ctx context.Context, sessionID string) error

func (*Client) ValidateSession

func (c *Client) ValidateSession(ctx context.Context, token string) (*Session, *User, error)

type ClientConfig

type ClientConfig struct {
	DB                           *sql.DB
	SessionInactivityTimeout     time.Duration
	SessionActivityCheckInterval time.Duration
	CookieName                   string
	CookieDomain                 string
	CookiePath                   string
	CookieSameSite               http.SameSite
	CookieSecure                 *bool
	CookieHTTPOnly               *bool
}

type Session

type Session struct {
	ID             string
	SecretHash     []byte
	UserID         string
	AuthLevel      int
	LastVerifiedAt time.Time
	CreatedAt      time.Time
}

func GetSession

func GetSession(ctx context.Context) *Session

type User

type User struct {
	ID            string
	Email         string
	EmailVerified bool
	CreatedAt     time.Time
}

func GetUser

func GetUser(ctx context.Context) *User

Jump to

Keyboard shortcuts

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