auth

package
v0.0.0-...-7c54f9f Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrUserNotFound represents the error when a user is not found.
	ErrUserNotFound = errors.New("user not found")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	TokenExpirationMinutes int    `long:"token_expiration_minutes" description:"Token expiration duration in minutes"`
	SessionSecret          string `long:"session_secret" description:"Session secret"`
}

func DefaultConfig

func DefaultConfig() *Config

DefaultConfig returns all default values for the Config struct.

type Controller

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

func NewController

func NewController(emailService *email.ResendService,
	invoiceProvider l402.InvoiceProvider, logger *slog.Logger,
	store Store, clock utils.Clock, cfg *Config) *Controller

func (*Controller) AuthMiddleware

func (c *Controller) AuthMiddleware() gin.HandlerFunc

func (*Controller) GetInvoicePreimage

func (c *Controller) GetInvoicePreimage(gCtx *gin.Context)

func (*Controller) LoginHandler

func (c *Controller) LoginHandler(gCtx *gin.Context)

func (*Controller) LogoutHandler

func (c *Controller) LogoutHandler(gCtx *gin.Context)

func (*Controller) MeHandler

func (c *Controller) MeHandler(gCtx *gin.Context)

func (*Controller) RegisterAuthMiddleware

func (c *Controller) RegisterAuthMiddleware(router *gin.Engine)

RegisterAuthMiddleware registers the authentication middleware.

func (*Controller) RegisterProtectedRoutes

func (c *Controller) RegisterProtectedRoutes(router *gin.Engine)

RegisterProtectedRoutes registers the protected authentication routes.

func (*Controller) RegisterPublicRoutes

func (c *Controller) RegisterPublicRoutes(router *gin.Engine)

RegisterPublicRoutes registers the public authentication routes.

func (*Controller) UpdateProfileHandler

func (c *Controller) UpdateProfileHandler(gCtx *gin.Context)

func (*Controller) VerifyTokenHandler

func (c *Controller) VerifyTokenHandler(gCtx *gin.Context)

VerifyTokenHandler verifies the user token sent with a magic link and sets the user session.

type InvoiceStatus

type InvoiceStatus struct {
	PaymentHash string    `json:"payment_hash"`
	Preimage    string    `json:"preimage"`
	Settled     bool      `json:"settled"`
	UpdatedAt   time.Time `json:"updated_at"`
	CreatedAt   time.Time `json:"created_at"`
}

type LoginRequest

type LoginRequest struct {
	Email string `json:"email" binding:"required,email"`
}

type Store

type Store interface {
	GetUserByID(ctx context.Context, id int64) (User, error)
	GetOrCreateUserByEmail(ctx context.Context, email string) (int64, error)
	UpdateUserLightningAddress(ctx context.Context, id int64,
		lightningAddress string) error
	UpdateUserVerified(ctx context.Context, email string, verified bool) error
	StoreToken(ctx context.Context, email, token string,
		expiration time.Time) error
	VerifyToken(ctx context.Context, token string) (string, error)

	// GetInvoiceStatus retrieves the invoice status for a given payment hash.
	// Used to cache requests.
	GetInvoiceStatus(ctx context.Context,
		paymentHash string) (*InvoiceStatus, error)

	// UpsertInvoiceStatus upserts the invoice status for a given payment hash.
	// and returns the updated invoice status.
	UpsertInvoiceStatus(ctx context.Context, paymentHash, preimage string,
		settled bool) (*InvoiceStatus, error)
}

type User

type User struct {
	ID               int64  `json:"id"`
	Email            string `json:"email"`
	LightningAddress string `json:"lightning_address"`
	Verified         bool   `json:"verified"`
}

Jump to

Keyboard shortcuts

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