auth

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: AGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUserNotFound        = errors.New("user not found")
	ErrUserAlreadyExists   = errors.New("user already exists")
	ErrInvalidToken        = errors.New("invalid token")
	ErrExpiredToken        = errors.New("token has expired")
	ErrMissingToken        = errors.New("token is required")
	ErrTokenAlreadyUsed    = errors.New("token already used")
	ErrInvalidRefreshToken = errors.New("invalid refresh token")
	ErrExpiredRefreshToken = errors.New("refresh token has expired")
	ErrRevokedRefreshToken = errors.New("refresh token has been revoked")
)

Functions

This section is empty.

Types

type AuthHandler

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

func NewAuthHandler

func NewAuthHandler(service service) *AuthHandler

func (*AuthHandler) Logout

func (h *AuthHandler) Logout(c *echo.Context) error

func (*AuthHandler) Refresh

func (h *AuthHandler) Refresh(c *echo.Context) error

func (*AuthHandler) Register

func (h *AuthHandler) Register(c *echo.Context) error
func (h *AuthHandler) RequestMagicLink(c *echo.Context) error

func (*AuthHandler) Verify

func (h *AuthHandler) Verify(c *echo.Context) error

func (*AuthHandler) VerifyRedirect

func (h *AuthHandler) VerifyRedirect(c *echo.Context) error

type AuthRepository

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

func NewAuthRepository

func NewAuthRepository(db *gorm.DB) *AuthRepository

func (*AuthRepository) CreateMagicLinkToken

func (r *AuthRepository) CreateMagicLinkToken(ctx context.Context, token MagicLinkToken) error

func (*AuthRepository) CreateRefreshToken

func (r *AuthRepository) CreateRefreshToken(ctx context.Context, token RefreshToken) error

func (*AuthRepository) GetMagicLinkToken

func (r *AuthRepository) GetMagicLinkToken(ctx context.Context, token string) (MagicLinkToken, error)

func (*AuthRepository) GetRefreshTokenByHash

func (r *AuthRepository) GetRefreshTokenByHash(ctx context.Context, hash string) (*RefreshToken, error)

func (*AuthRepository) MarkMagicLinkTokenAsUsed

func (r *AuthRepository) MarkMagicLinkTokenAsUsed(ctx context.Context, tokenId uuid.UUID) error

func (*AuthRepository) RevokeAllUserRefreshTokens

func (r *AuthRepository) RevokeAllUserRefreshTokens(ctx context.Context, userID uuid.UUID) error

func (*AuthRepository) RevokeRefreshToken

func (r *AuthRepository) RevokeRefreshToken(ctx context.Context, tokenID uuid.UUID) error

type AuthService

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

func NewAuthService

func NewAuthService(repository repository, users userRepository, emailSender emailSender,
	jwtManager *utils.JWTManager, magicLinkTokenDuration time.Duration, refreshTokenDuration time.Duration) *AuthService
func (s *AuthService) CreateMagicLink(ctx context.Context, email string) error
func (s *AuthService) LoginWithMagicLink(ctx context.Context, token string) (*LoginResponse, error)

func (*AuthService) Logout

func (s *AuthService) Logout(ctx context.Context, rawRefreshToken string) error

func (*AuthService) RefreshAccessToken

func (s *AuthService) RefreshAccessToken(ctx context.Context, rawRefreshToken string) (*LoginResponse, error)

func (*AuthService) Register

func (s *AuthService) Register(ctx context.Context, email string, name string) error

type LoginResponse

type LoginResponse struct {
	AccessToken  string `json:"access_token"`
	RefreshToken string `json:"refresh_token"`
}

type LogoutRequest

type LogoutRequest struct {
	RefreshToken string `json:"refresh_token" validate:"required"`
}

type MagicLinkRequest

type MagicLinkRequest struct {
	Email string `json:"email" validate:"required,email"`
}

type MagicLinkToken

type MagicLinkToken struct {
	TokenID   uuid.UUID  `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	UserID    uuid.UUID  `gorm:"not null;index"`
	Email     string     `gorm:"not null"`
	Token     string     `gorm:"not null;uniqueIndex"`
	ExpiresAt time.Time  `gorm:"not null"`
	UsedAt    *time.Time `gorm:"index"`
}

type RefreshRequest

type RefreshRequest struct {
	RefreshToken string `json:"refresh_token" validate:"required"`
}

type RefreshToken

type RefreshToken struct {
	TokenID   uuid.UUID `gorm:"primaryKey;type:uuid;default:gen_random_uuid()"`
	UserID    uuid.UUID `gorm:"not null;index"`
	TokenHash string    `gorm:"column:token_hash;not null;uniqueIndex"`
	ExpiresAt time.Time `gorm:"not null"`
	CreatedAt time.Time `gorm:"autoCreateTime"`
	RevokedAt *time.Time
}

type RegisterRequest

type RegisterRequest struct {
	Email string `json:"email" validate:"required,email"`
	Name  string `json:"name" validate:"required"`
}

type VerifyRequest

type VerifyRequest struct {
	Token string `json:"token" validate:"required"`
}

Jump to

Keyboard shortcuts

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