magiclink

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Jan 3, 2026 License: Apache-2.0 Imports: 28 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	// ExpiryMinutes is the magic link expiry time in minutes
	ExpiryMinutes int `json:"expiryMinutes"`
	// BaseURL is the base URL for magic link generation
	BaseURL string `json:"baseURL"`
	// AllowImplicitSignup allows creating users if they don't exist
	AllowImplicitSignup bool `json:"allowImplicitSignup"`
	// RateLimitPerHour is the max requests per hour per user
	RateLimitPerHour int `json:"rateLimitPerHour"`

	DevExposeURL bool `json:"devExposeURL"`
}

Config holds the magic link plugin configuration

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the default magic link plugin configuration

type ErrorResponse

type ErrorResponse = responses.ErrorResponse

Response types

type Handler

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

func NewHandler

func NewHandler(s *Service, rls *rl.Service, authInst core.Authsome, authCompletion *authflow.CompletionService) *Handler

func (*Handler) Send

func (h *Handler) Send(c forge.Context) error

func (*Handler) Verify

func (h *Handler) Verify(c forge.Context) error

type Plugin

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

func NewPlugin

func NewPlugin(opts ...PluginOption) *Plugin

NewPlugin creates a new magic link plugin instance with optional configuration

func (*Plugin) ID

func (p *Plugin) ID() string

func (*Plugin) Init

func (p *Plugin) Init(authInst core.Authsome) error

func (*Plugin) Migrate

func (p *Plugin) Migrate() error

func (*Plugin) RegisterHooks

func (p *Plugin) RegisterHooks(_ *hooks.HookRegistry) error

func (*Plugin) RegisterRoutes

func (p *Plugin) RegisterRoutes(router forge.Router) error

func (*Plugin) RegisterServiceDecorators

func (p *Plugin) RegisterServiceDecorators(_ *registry.ServiceRegistry) error

type PluginOption

type PluginOption func(*Plugin)

PluginOption is a functional option for configuring the magic link plugin

func WithAllowImplicitSignup

func WithAllowImplicitSignup(allow bool) PluginOption

WithAllowImplicitSignup sets whether implicit signup is allowed

func WithBaseURL

func WithBaseURL(url string) PluginOption

WithBaseURL sets the base URL for magic links

func WithDefaultConfig

func WithDefaultConfig(cfg Config) PluginOption

WithDefaultConfig sets the default configuration for the plugin

func WithExpiryMinutes

func WithExpiryMinutes(minutes int) PluginOption

WithExpiryMinutes sets the magic link expiry time

func WithRateLimitPerHour

func WithRateLimitPerHour(limit int) PluginOption

WithRateLimitPerHour sets the rate limit per hour

type SendRequest

type SendRequest struct {
	Email string `json:"email" validate:"required,email" example:"user@example.com"`
}

Request types

type SendResponse

type SendResponse struct {
	Status string `json:"status" example:"sent"`
	DevURL string `json:"dev_url,omitempty" example:"http://localhost:3000/magic-link/verify?token=abc123"`
}

type Service

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

func NewService

func NewService(r *repo.MagicLinkRepository, users *user.Service, sessionSvc *session.Service, authSvc *auth.Service, auditSvc *audit.Service, notifAdapter *notificationPlugin.Adapter, cfg Config) *Service

func (*Service) Send

func (s *Service) Send(ctx context.Context, appID xid.ID, email, ip, ua string) (string, error)

func (*Service) Verify

func (s *Service) Verify(ctx context.Context, appID, envID xid.ID, orgID *xid.ID, token string, remember bool, ip, ua string) (*VerifyResult, error)

type VerifyResponse

type VerifyResponse = responses.VerifyResponse

type VerifyResult added in v0.0.7

type VerifyResult struct {
	Email     string     // Email from magic link
	User      *user.User // Nil for new users, populated for existing users
	IsNewUser bool       // True if this is a new user signup
	AppID     xid.ID     // App ID for context
	EnvID     xid.ID     // Environment ID for context
	OrgID     *xid.ID    // Optional organization ID
}

VerifyResult holds the result of magic link verification

Jump to

Keyboard shortcuts

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