auth

package
v0.0.0-...-99fda48 Latest Latest
Warning

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

Go to latest
Published: Jun 5, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCredentials = errors.New("invalid credentials")
	ErrInvalidAppId       = errors.New("invalid appId")
	ErrInvalidUserId      = errors.New("invalid userId")
	ErrUserAlreadyExists  = errors.New("user already exists")
)

Functions

This section is empty.

Types

type IsAdminDTO

type IsAdminDTO struct {
	UserId int
}

type LoginDTO

type LoginDTO struct {
	Email    string
	Password string
	AppId    int
}

type RegisterDTO

type RegisterDTO struct {
	Email    string
	Password string
}

type Service

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

func New

func New(
	log *slog.Logger,
	userRepo userRepository,
	appRepo appRepository,
	adminRepo adminRepository,
	tokenManager tokenManager,
	secretManager secretManager,
	hasher hasher,
	accessTokenTTL time.Duration,
	refreshTokenTTL time.Duration,
) *Service

New creates new auth Service

func (*Service) IsAdmin

func (s *Service) IsAdmin(ctx context.Context, dto IsAdminDTO) (bool, error)

IsAdmin checks if user is admin

If user doesn't exist, returns error ErrInvalidUserId

func (*Service) Login

func (s *Service) Login(ctx context.Context, dto LoginDTO) (string, error)

Login checks if user with given credentials exists in the system

If user exists, but password is incorrect, returns error ErrInvalidCredentials If user doesn't exist, returns error ErrInvalidCredentials If app doesn't exist, returns error ErrInvalidAppId

func (*Service) Register

func (s *Service) Register(ctx context.Context, dto RegisterDTO) (int64, error)

Register creates new user in the system

If user with the same email already exists, returns error ErrUserAlreadyExists

Jump to

Keyboard shortcuts

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