auth

package
v0.0.0-...-71aa9d5 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCredentials = errors.New("invalid credentials")
	ErrInvalidAppID       = errors.New("invalid app id")
	ErrUserExists         = errors.New("user already exists")
	ErrUserNotFound       = errors.New("user not found")
)

Functions

This section is empty.

Types

type AppProvider

type AppProvider interface {
	App(ctx context.Context, appID int) (*models.App, error)
}

type Auth

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

func New

func New(log *slog.Logger, userSaver UserSaver, userProvider UserProvider, appProvider AppProvider, tokenTTL time.Duration) *Auth

New returns a new instance of the Auth service.

func (*Auth) IsAdmin

func (a *Auth) IsAdmin(ctx context.Context, userID int) (bool, error)

IsAdmin checks if user is admin.

func (*Auth) Login

func (a *Auth) Login(ctx context.Context, email string, password string, appID int) (string, error)

Login checks if user with given credentials exists in the system and returns access token.

If user exists, but password is incorrect, returns error. If user doesn't exist, returns error.

func (*Auth) RegisterNewUser

func (a *Auth) RegisterNewUser(ctx context.Context, email string, password string) (int, error)

RegisterNewUser registers new user in the system and returns user ID. If user with given username already exists, returns error.

type UserProvider

type UserProvider interface {
	User(ctx context.Context, email string) (*models.User, error)
	IsAdmin(ctx context.Context, userID int) (bool, error)
}

type UserSaver

type UserSaver interface {
	SaveUser(ctx context.Context, email string, passHash []byte) (uid int, err error)
}

Jump to

Keyboard shortcuts

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