facade

package
v0.0.0-...-1842cec Latest Latest
Warning

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

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrResendVerificationNoEmail   = errors.New("resend verification: user has no email")
	ErrVerifyEmailUserNotFound     = errors.New("verify email: user not found")
	ErrVerifyEmailAlreadyVerified  = errors.New("verify email: already verified")
	ErrVerifyEmailInvalidOrExpired = errors.New("verify email: invalid or expired code")
	ErrSendVerifyEmailUnsubscribed = errors.New("send verify email: user is unsubscribed")
)

errors

View Source
var (
	// ErrRefreshTokenNotFound is returned when refresh token is not found
	ErrRefreshTokenNotFound = errors.New("refresh token not found")
	// ErrRefreshTokenExpired is returned when refresh token has expired
	ErrRefreshTokenExpired = errors.New("refresh token expired")
)
View Source
var (
	ErrInvalidEmail                 = errors.New("invalid email")
	ErrOAuthSignInConflict          = errors.New("oauth sign in name conflict")
	ErrUpdateProfileUserNotFound    = errors.New("update profile: user not found")
	ErrUpdateProfileInvalidPassword = errors.New("update profile: invalid current password")
	ErrUpdateProfileNotAllowed      = errors.New("update profile: password change not allowed for oauth users")
	ErrSignInInvalidCredentials     = errors.New("sign in: invalid credentials")
	ErrSignUpUsernameExists         = errors.New("sign up: username already exists")
	ErrSignUpEmailExists            = errors.New("sign up: email already exists")
	ErrSignUpEmailRequired          = errors.New("sign up: email is required")
	ErrSignUpPublisherNameExists    = errors.New("sign up: publisher name already exists")
	ErrOAuthPublisherConflict       = errors.New("oauth sign in: publisher must use password")
	ErrOAuthEmailUnverified         = errors.New("oauth sign in: email not verified by provider")
)

errors

Functions

This section is empty.

Types

type Auth

type Auth interface {
	GenerateToken(claims jwt.Claims) (string, error)
	GenerateRefreshToken() (string, time.Time, error)
	CreateUserClaims(user model.User) jwt.Claims
	GetClaimsFromToken(tokenStr string) (auth.Claims, error)
}

Auth provides authentication methods

type EmailSender

type EmailSender interface {
	SendEmailVerification(ctx context.Context, req resendapi.SendEmailVerificationRequest) (string, error)
}

EmailSender provides methods for sending emails

type InfoAPIClient

type InfoAPIClient interface {
	CompanyExists(ctx context.Context, companyName string) (bool, error)
}

InfoAPIClient provides methods for interacting with game library info API

type Provider

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

Provider represents dependencies for facade layer

func New

func New(log *zap.Logger, userRepo UserRepo, emailSender EmailSender, authService Auth, unsubscribeTokenGenerator *auth.UnsubscribeTokenGenerator, infoAPIClient InfoAPIClient) *Provider

New creates a new facade provider

func (*Provider) CreateRefreshToken

func (p *Provider) CreateRefreshToken(ctx context.Context, userID string) (RefreshToken, error)

CreateRefreshToken creates a refresh token for the user

func (*Provider) CreateTokens

func (p *Provider) CreateTokens(ctx context.Context, user model.User) (TokenPair, error)

CreateTokens creates access token and refresh token for a user

func (*Provider) DeleteUser

func (p *Provider) DeleteUser(ctx context.Context, userID string) error

DeleteUser deletes user by id

func (*Provider) GetClaimsFromAccessToken

func (p *Provider) GetClaimsFromAccessToken(tokenStr string) (auth.Claims, error)

GetClaimsFromAccessToken returns claims from access token

func (*Provider) GitHubOAuth

func (p *Provider) GitHubOAuth(ctx context.Context, oauthID, email, username string, emailVerified bool) (model.User, error)

GitHubOAuth handles GitHub OAuth sign in

func (*Provider) GoogleOAuth

func (p *Provider) GoogleOAuth(ctx context.Context, oauthID, email string, emailVerified bool) (model.User, error)

GoogleOAuth handles Google OAuth sign in

func (*Provider) IsEmailUnsubscribed

func (p *Provider) IsEmailUnsubscribed(ctx context.Context, email string) (bool, error)

IsEmailUnsubscribed checks if an email address is unsubscribed from all notifications

func (*Provider) RefreshTokens

func (p *Provider) RefreshTokens(ctx context.Context, refreshTokenStr string) (TokenPair, error)

RefreshTokens validates refresh token and returns new access and refresh tokens

func (*Provider) ResendVerificationEmail

func (p *Provider) ResendVerificationEmail(ctx context.Context, userID string) error

ResendVerificationEmail resends email verification code to a user

func (*Provider) RevokeRefreshToken

func (p *Provider) RevokeRefreshToken(ctx context.Context, refreshTokenStr string) error

RevokeRefreshToken revokes a refresh token by deleting it from the database

func (*Provider) SignIn

func (p *Provider) SignIn(ctx context.Context, username, password string) (model.User, error)

SignIn authenticates user by username/email and password

func (*Provider) SignUp

func (p *Provider) SignUp(ctx context.Context, username, displayName, email, password string, isPublisher bool) (model.User, error)

SignUp creates a new user with provided params and sends verification email if applicable

func (*Provider) UnsubscribeEmail

func (p *Provider) UnsubscribeEmail(ctx context.Context, token string) (string, error)

UnsubscribeEmail unsubscribes an email address from all notifications

func (*Provider) UpdateUserProfile

func (p *Provider) UpdateUserProfile(ctx context.Context, userID string, params model.UpdateProfileParams) (model.User, error)

UpdateUserProfile updates user profile

func (*Provider) ValidateAccessToken

func (p *Provider) ValidateAccessToken(tokenStr string) bool

ValidateAccessToken validates access token and returns claims from it

func (*Provider) VerifyEmail

func (p *Provider) VerifyEmail(ctx context.Context, userID string, code string) (model.User, error)

VerifyEmail verifies user email by provided code

type RefreshToken

type RefreshToken struct {
	Token     string
	ExpiresAt time.Time
}

RefreshToken represents a refresh token

type TokenPair

type TokenPair struct {
	AccessToken  string
	RefreshToken RefreshToken
}

TokenPair represents an access token and refresh token pair

type TooManyRequestsError

type TooManyRequestsError struct {
	RetryAfter time.Duration
}

TooManyRequestsError - error with retry after

func AsTooManyRequestsError

func AsTooManyRequestsError(err error) *TooManyRequestsError

AsTooManyRequestsError - returns *TooManyRequestsError if err is of type TooManyRequestsError

func NewTooManyRequestsError

func NewTooManyRequestsError(retryAfter time.Duration) TooManyRequestsError

NewTooManyRequestsError - creates a new ErrTooManyRequestsRetryAfter

func (TooManyRequestsError) Error

func (e TooManyRequestsError) Error() string

Error implements error interface

type UserRepo

type UserRepo interface {
	RunWithTx(ctx context.Context, f func(context.Context) error) error

	CreateUser(ctx context.Context, user database.User) error
	UpdateUser(ctx context.Context, user database.User) error
	DeleteUser(ctx context.Context, userID string) error
	GetUserByID(ctx context.Context, userID string) (database.User, error)
	GetUserByUsername(ctx context.Context, username string) (database.User, error)
	GetUserByEmail(ctx context.Context, email string) (database.User, error)
	GetUserByOAuthLink(ctx context.Context, provider string, oauthID string) (database.User, error)
	CreateUserOAuthLink(ctx context.Context, link database.UserOAuthLink) error
	HasOAuthLink(ctx context.Context, userID string) (bool, error)
	CheckUserExists(ctx context.Context, name string, role model.Role) (bool, error)
	SetUserEmailVerified(ctx context.Context, userID string) error

	CreateEmailVerification(ctx context.Context, verification database.EmailVerification) error
	GetEmailVerificationByUserID(ctx context.Context, userID string) (database.EmailVerification, error)
	SetEmailVerificationMessageID(ctx context.Context, verificationID string, messageID string) error
	SetEmailVerificationUsed(ctx context.Context, id string, verified bool) error
	SetUnsubscribeToken(ctx context.Context, id string, token string) error

	CreateEmailUnsubscribe(ctx context.Context, unsubscribe database.EmailUnsubscribe) error
	IsEmailUnsubscribed(ctx context.Context, email string) (bool, error)

	CreateRefreshToken(ctx context.Context, refreshToken database.RefreshToken) error
	GetRefreshTokenByHash(ctx context.Context, tokenHash string) (database.RefreshToken, error)
	DeleteRefreshToken(ctx context.Context, token string) error
	DeleteRefreshTokensByUserID(ctx context.Context, userID string) error
}

UserRepo provides methods for working with user repo

Directories

Path Synopsis
Package facade_mocks is a generated GoMock package.
Package facade_mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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