cauth

package
v0.0.0-...-5538d7f Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2021 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCredentials = errors.New("invalid credentials")

ErrInvalidCredentials is returned by UsersSvc when the given credentials such as email/password or session token are incorrect.

View Source
var ErrUserAlreadyExists = errors.New("user already exists")

ErrUserAlreadyExists is returned by UsersSvc when a user already exists. For example, signing up with an email with which a user already exists.

View Source
var ErrUserNotFound = gorm.ErrRecordNotFound

ErrUserNotFound is returned when the user is not found when queried by a unique attribute such as id or email.

View Source
var FxMigrations = fx.Invoke(
	RunMigrations,
)

Functions

func GetCurrentUserUUID

func GetCurrentUserUUID(ctx context.Context) string

func RunMigrations

func RunMigrations(db *gorm.DB) error

Types

type Middleware

type Middleware interface {
	VerifySessionToken(next http.Handler) http.Handler
}

func NewAuthMiddleware

func NewAuthMiddleware(p MiddlewareParams) Middleware

type MiddlewareParams

type MiddlewareParams struct {
	fx.In

	RW     chttp.ReaderWriter
	Svc    Svc
	Logger clogger.Logger

	ACL cacl.Svc `optional:"true"`
}

type Module

type Module struct {
	Svc        Svc
	Middleware Middleware
}

func NewModule

func NewModule(db *gorm.DB, logger clogger.Logger) *Module

type Repo

type Repo interface {
	GetUser(ctx context.Context, uuid string) (*User, error)
	AddUser(ctx context.Context, user *User) error
}

func NewSQLRepo

func NewSQLRepo(db *gorm.DB) Repo

type Svc

type Svc interface {
	CreateUser(ctx context.Context) (*User, error)
	VerifySessionToken(ctx context.Context, userUUID, token string) (bool, error)
	ResetSessionToken(ctx context.Context, userUUID string) (string, error)
}

func NewSvc

func NewSvc(repo Repo) Svc

type User

type User struct {
	ID        uint      `gorm:"primaryKey"`
	CreatedAt time.Time `gorm:"not null"`
	UpdatedAt time.Time `gorm:"not null"`

	UUID         string `gorm:"uniqueIndex;not null"`
	SessionToken string `gorm:"not null"`
}

func (User) TableName

func (User) TableName() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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