Documentation
¶
Index ¶
- Variables
- type Config
- type ErrorResponse
- type Handler
- type PhoneVerifyResponse
- type Plugin
- func (p *Plugin) ID() string
- func (p *Plugin) Init(authInst core.Authsome) error
- func (p *Plugin) Migrate() error
- func (p *Plugin) RegisterHooks(_ *hooks.HookRegistry) error
- func (p *Plugin) RegisterRoutes(router forge.Router) error
- func (p *Plugin) RegisterServiceDecorators(_ *registry.ServiceRegistry) error
- type PluginOption
- func WithAllowImplicitSignup(allow bool) PluginOption
- func WithCodeLength(length int) PluginOption
- func WithDefaultConfig(cfg Config) PluginOption
- func WithDevExposeCode(expose bool) PluginOption
- func WithExpiryMinutes(minutes int) PluginOption
- func WithMaxAttempts(max int) PluginOption
- func WithRateLimitSendCodePerPhone(window time.Duration, max int) PluginOption
- func WithSMSProvider(provider string) PluginOption
- type RateLimitConfig
- type RateLimitRule
- type SendCodeRequest
- type SendCodeResponse
- type Service
- type VerifyRequest
Constants ¶
This section is empty.
Variables ¶
var ( // Common errors ErrInvalidPhoneFormat = errors.New("invalid phone number format, must be E.164 format (e.g., +1234567890)") ErrMissingPhone = errors.New("phone number is required") ErrMissingCode = errors.New("verification code is required") ErrMissingEmail = errors.New("email is required") ErrCodeExpired = errors.New("verification code not found or expired") ErrTooManyAttempts = errors.New("too many verification attempts, please request a new code") ErrInvalidCode = errors.New("invalid verification code") )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// CodeLength is the length of the verification code
CodeLength int `json:"codeLength"`
// ExpiryMinutes is the code expiry time in minutes
ExpiryMinutes int `json:"expiryMinutes"`
// MaxAttempts is the maximum verification attempts
MaxAttempts int `json:"maxAttempts"`
// AllowImplicitSignup allows creating users if they don't exist
AllowImplicitSignup bool `json:"allowImplicitSignup"`
// SMSProvider is the SMS provider to use (twilio, etc.)
SMSProvider string `json:"smsProvider"`
// DevExposeCode exposes the code in dev mode (for testing)
DevExposeCode bool `json:"devExposeCode"`
// Rate limiting configuration
RateLimit RateLimitConfig `json:"rateLimit"`
}
Config holds the phone plugin configuration
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig returns the default phone plugin configuration
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
type PhoneVerifyResponse ¶
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
func NewPlugin ¶
func NewPlugin(opts ...PluginOption) *Plugin
NewPlugin creates a new phone plugin instance with optional configuration
func (*Plugin) RegisterHooks ¶
func (p *Plugin) RegisterHooks(_ *hooks.HookRegistry) 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 phone plugin
func WithAllowImplicitSignup ¶
func WithAllowImplicitSignup(allow bool) PluginOption
WithAllowImplicitSignup sets whether implicit signup is allowed
func WithCodeLength ¶
func WithCodeLength(length int) PluginOption
WithCodeLength sets the verification code length
func WithDefaultConfig ¶
func WithDefaultConfig(cfg Config) PluginOption
WithDefaultConfig sets the default configuration for the plugin
func WithDevExposeCode ¶
func WithDevExposeCode(expose bool) PluginOption
WithDevExposeCode sets whether to expose codes in dev mode
func WithExpiryMinutes ¶
func WithExpiryMinutes(minutes int) PluginOption
WithExpiryMinutes sets the code expiry time
func WithMaxAttempts ¶
func WithMaxAttempts(max int) PluginOption
WithMaxAttempts sets the maximum verification attempts
func WithRateLimitSendCodePerPhone ¶
func WithRateLimitSendCodePerPhone(window time.Duration, max int) PluginOption
WithRateLimitSendCodePerPhone sets the send code rate limit per phone
func WithSMSProvider ¶
func WithSMSProvider(provider string) PluginOption
WithSMSProvider sets the SMS provider
type RateLimitConfig ¶
type RateLimitConfig struct {
// Enabled enables rate limiting
Enabled bool `json:"enabled"`
// UseRedis uses Redis for distributed rate limiting (recommended for production)
UseRedis bool `json:"useRedis"`
// RedisAddr is the Redis server address (e.g., "localhost:6379")
RedisAddr string `json:"redisAddr"`
// RedisPassword is the Redis password (optional)
RedisPassword string `json:"redisPassword"`
// RedisDB is the Redis database number
RedisDB int `json:"redisDb"`
// SendCodePerPhone limits send code requests per phone number
SendCodePerPhone RateLimitRule `json:"sendCodePerPhone"`
// SendCodePerIP limits send code requests per IP address
SendCodePerIP RateLimitRule `json:"sendCodePerIp"`
// VerifyPerPhone limits verify requests per phone number
VerifyPerPhone RateLimitRule `json:"verifyPerPhone"`
// VerifyPerIP limits verify requests per IP address
VerifyPerIP RateLimitRule `json:"verifyPerIp"`
}
RateLimitConfig holds rate limiting configuration
type RateLimitRule ¶
type RateLimitRule struct {
// Window is the time window for the rate limit (e.g., "1m", "1h")
Window time.Duration `json:"window"`
// Max is the maximum number of requests in the window
Max int `json:"max"`
}
RateLimitRule defines a rate limit rule
type SendCodeRequest ¶
type SendCodeRequest struct {
Phone string `json:"phone" validate:"required" example:"+1234567890"`
}
Request types
type SendCodeResponse ¶
type SendCodeResponse struct {
Status string `json:"status" example:"sent"`
DevCode string `json:"dev_code,omitempty" example:"123456"`
}
Response types
type Service ¶
type Service struct {
// contains filtered or unexported fields
}