auth

package
v0.0.0-...-a0facd0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 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")
)

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 int64) (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, return error.

func (*Auth) RegisterNewUser

func (a *Auth) RegisterNewUser(ctx context.Context, email string, pass string) (int64, error)

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

type UserProvider

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

type UserSaver

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

Jump to

Keyboard shortcuts

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