auth

package
v0.0.0-...-b48969e Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

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

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

func (*Auth) IsAdmin

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

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, pass string) (int64, 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)
}

type UserSaver

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

type UserStorage

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

Jump to

Keyboard shortcuts

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