session

package
v0.0.0-...-f79cf23 Latest Latest
Warning

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

Go to latest
Published: Mar 25, 2024 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const ErrForbidden = errs.Sentinel("forbidden")

Variables

This section is empty.

Functions

func CheckForbidden

func CheckForbidden(err error) error

CheckForbidden checks if the error is the internal Postgres database row-level security policy violation exception or a permission denied exception due to insufficient grants and returns ErrForbidden.

If the error is not a Postgres forbidden error, the passed error will be returned instead.

func ContextWithUser

func ContextWithUser(ctx context.Context, userID uu.ID) context.Context

func Handler

func Handler(wrappedHandler http.Handler) http.HandlerFunc

func HandlerWithUserIDAsMuxVar

func HandlerWithUserIDAsMuxVar(muxVarName string, wrappedHandler http.Handler) http.HandlerFunc

func IsOtherThanErrForbidden

func IsOtherThanErrForbidden(err error) bool

IsOtherThanErrForbidden returns true if the error is present and is not ErrForbidden.

func TransactionAsUser

func TransactionAsUser(ctx context.Context, userID uu.ID, txFunc func(ctx context.Context) error) (err error)

func TransactionAsUserFromContext

func TransactionAsUserFromContext(ctx context.Context, txFunc func(ctx context.Context) error) (err error)

func UserFromContext

func UserFromContext(ctx context.Context) (userID uu.ID, err error)

Types

type SameSite

type SameSite string

SameSite attribute of the Set-Cookie HTTP response header allows you to declare if your cookie should be restricted to a first-party or same-site context.

const (
	// Cookies will only be sent in a first-party context and not be sent along with requests
	// initiated by third party websites.
	SameSiteStrict SameSite = "strict"
	// Cookies are not sent on normal cross-site subrequests (for example to load images
	// or frames into a third party site), but are sent when a user is navigating to the
	// origin site (i.e., when following a link).
	// This is the default cookie value if SameSite has not been explicitly specified in
	// recent browser versions.
	// Note: Lax replaced None as the default value in order to ensure that users have
	// reasonably robust defense against some classes of cross-site request forgery (CSRF)
	// attacks.
	SameSiteLax SameSite = "lax"
	// Cookies will be sent in all contexts, i.e. in responses to both first-party and cross-origin
	// requests. If SameSite=None is set, the cookie Secure attribute must also be set (or the cookie
	// will be blocked).
	SameSiteNone SameSite = "none"
)

func (SameSite) HTTPSameSite

func (ss SameSite) HTTPSameSite() http.SameSite

func (*SameSite) UnmarshalJSON

func (ss *SameSite) UnmarshalJSON(j []byte) error

UnmarshalJSON implements encoding/json.Unmarshaler

type Session

type Session struct {
	ID uu.ID `db:"id,pk"`

	UserID uu.ID          `db:"user_id"`
	Cookie *SessionCookie `db:"cookie"`
	Data   interface{}    `db:"data"`

	ExpiresAt time.Time `db:"expires_at"`

	UpdatedAt time.Time `db:"updated_at"`
	CreatedAt time.Time `db:"created_at"`
}

Session is the user cookie session stored. See database/schema/private/session.sql@private.session

type SessionCookie

type SessionCookie struct {
	Domain   string   `json:"domain"`
	Path     string   `json:"path"`
	Secure   bool     `json:"secure"`
	MaxAge   int      `json:"maxAge"`
	HTTPOnly bool     `json:"httpOnly"`
	SameSite SameSite `json:"sameSite"`
}

SessionCookie is the session cookie and it matches the SessionCookie in graphql/src/session.ts@SessionCookie

func (*SessionCookie) Scan

func (v *SessionCookie) Scan(value interface{}) error

func (SessionCookie) Value

func (v SessionCookie) Value() (driver.Value, error)

Jump to

Keyboard shortcuts

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