Versions in this module Expand all Collapse all v1 v1.1.0 Jun 26, 2026 v1.0.0 Apr 29, 2026 Changes in this version + var ErrInvalidEmail = errors.New("invalid email") + var ErrOAuthEmailUnverified = errors.New("oauth sign in: email not verified by provider") + var ErrOAuthPublisherConflict = errors.New("oauth sign in: publisher must use password") + var ErrOAuthSignInConflict = errors.New("oauth sign in name conflict") + var ErrRefreshTokenExpired = errors.New("refresh token expired") + var ErrRefreshTokenNotFound = errors.New("refresh token not found") + var ErrResendVerificationNoEmail = errors.New("resend verification: user has no email") + var ErrSendVerifyEmailUnsubscribed = errors.New("send verify email: user is unsubscribed") + var ErrSignInInvalidCredentials = errors.New("sign in: invalid credentials") + var ErrSignUpEmailExists = errors.New("sign up: email already exists") + var ErrSignUpEmailRequired = errors.New("sign up: email is required") + var ErrSignUpPublisherNameExists = errors.New("sign up: publisher name already exists") + var ErrSignUpUsernameExists = errors.New("sign up: username already exists") + var ErrUpdateProfileInvalidPassword = errors.New("update profile: invalid current password") + var ErrUpdateProfileNotAllowed = errors.New("update profile: password change not allowed for oauth users") + var ErrUpdateProfileUserNotFound = errors.New("update profile: user not found") + var ErrVerifyEmailAlreadyVerified = errors.New("verify email: already verified") + var ErrVerifyEmailInvalidOrExpired = errors.New("verify email: invalid or expired code") + var ErrVerifyEmailUserNotFound = errors.New("verify email: user not found") + type Auth interface + CreateUserClaims func(user model.User) jwt.Claims + GenerateRefreshToken func() (string, time.Time, error) + GenerateToken func(claims jwt.Claims) (string, error) + GetClaimsFromToken func(tokenStr string) (auth.Claims, error) + type EmailSender interface + SendEmailVerification func(ctx context.Context, req resendapi.SendEmailVerificationRequest) (string, error) + type InfoAPIClient interface + CompanyExists func(ctx context.Context, companyName string) (bool, error) + type Provider struct + func New(log *zap.Logger, userRepo UserRepo, emailSender EmailSender, authService Auth, ...) *Provider + func (p *Provider) CreateRefreshToken(ctx context.Context, userID string) (RefreshToken, error) + func (p *Provider) CreateTokens(ctx context.Context, user model.User) (TokenPair, error) + func (p *Provider) DeleteUser(ctx context.Context, userID string) error + func (p *Provider) GetClaimsFromAccessToken(tokenStr string) (auth.Claims, error) + func (p *Provider) GitHubOAuth(ctx context.Context, oauthID, email, username string, emailVerified bool) (model.User, error) + func (p *Provider) GoogleOAuth(ctx context.Context, oauthID, email string, emailVerified bool) (model.User, error) + func (p *Provider) IsEmailUnsubscribed(ctx context.Context, email string) (bool, error) + func (p *Provider) RefreshTokens(ctx context.Context, refreshTokenStr string) (TokenPair, error) + func (p *Provider) ResendVerificationEmail(ctx context.Context, userID string) error + func (p *Provider) RevokeRefreshToken(ctx context.Context, refreshTokenStr string) error + func (p *Provider) SignIn(ctx context.Context, username, password string) (model.User, error) + func (p *Provider) SignUp(ctx context.Context, username, displayName, email, password string, ...) (model.User, error) + func (p *Provider) UnsubscribeEmail(ctx context.Context, token string) (string, error) + func (p *Provider) UpdateUserProfile(ctx context.Context, userID string, params model.UpdateProfileParams) (model.User, error) + func (p *Provider) ValidateAccessToken(tokenStr string) bool + func (p *Provider) VerifyEmail(ctx context.Context, userID string, code string) (model.User, error) + type RefreshToken struct + ExpiresAt time.Time + Token string + type TokenPair struct + AccessToken string + RefreshToken RefreshToken + type TooManyRequestsError struct + RetryAfter time.Duration + func AsTooManyRequestsError(err error) *TooManyRequestsError + func NewTooManyRequestsError(retryAfter time.Duration) TooManyRequestsError + func (e TooManyRequestsError) Error() string + type UserRepo interface + CheckUserExists func(ctx context.Context, name string, role model.Role) (bool, error) + CreateEmailUnsubscribe func(ctx context.Context, unsubscribe database.EmailUnsubscribe) error + CreateEmailVerification func(ctx context.Context, verification database.EmailVerification) error + CreateRefreshToken func(ctx context.Context, refreshToken database.RefreshToken) error + CreateUser func(ctx context.Context, user database.User) error + CreateUserOAuthLink func(ctx context.Context, link database.UserOAuthLink) error + DeleteRefreshToken func(ctx context.Context, token string) error + DeleteRefreshTokensByUserID func(ctx context.Context, userID string) error + DeleteUser func(ctx context.Context, userID string) error + GetEmailVerificationByUserID func(ctx context.Context, userID string) (database.EmailVerification, error) + GetRefreshTokenByHash func(ctx context.Context, tokenHash string) (database.RefreshToken, error) + GetUserByEmail func(ctx context.Context, email string) (database.User, error) + GetUserByID func(ctx context.Context, userID string) (database.User, error) + GetUserByOAuthLink func(ctx context.Context, provider string, oauthID string) (database.User, error) + GetUserByUsername func(ctx context.Context, username string) (database.User, error) + HasOAuthLink func(ctx context.Context, userID string) (bool, error) + IsEmailUnsubscribed func(ctx context.Context, email string) (bool, error) + RunWithTx func(ctx context.Context, f func(context.Context) error) error + SetEmailVerificationMessageID func(ctx context.Context, verificationID string, messageID string) error + SetEmailVerificationUsed func(ctx context.Context, id string, verified bool) error + SetUnsubscribeToken func(ctx context.Context, id string, token string) error + SetUserEmailVerified func(ctx context.Context, userID string) error + UpdateUser func(ctx context.Context, user database.User) error