Documentation
¶
Index ¶
- Constants
- type Account
- type AccountDatabaseHooksConfig
- type AccountService
- type ApiMiddleware
- type AuthApi
- type AuthServices
- type AuthSettings
- type BasePlugin
- func (p *BasePlugin) Close() error
- func (p *BasePlugin) Config() PluginConfig
- func (p *BasePlugin) Ctx() *PluginContext
- func (p *BasePlugin) DatabaseHooks() any
- func (p *BasePlugin) EndpointHooks() any
- func (p *BasePlugin) EventHooks() any
- func (p *BasePlugin) Init(ctx *PluginContext) error
- func (p *BasePlugin) Metadata() PluginMetadata
- func (p *BasePlugin) Migrations() []any
- func (p *BasePlugin) RateLimit() *PluginRateLimit
- func (p *BasePlugin) Routes() []PluginRoute
- func (p *BasePlugin) SetClose(fn func() error)
- func (p *BasePlugin) SetConfig(config PluginConfig)
- func (p *BasePlugin) SetCtx(ctx *PluginContext)
- func (p *BasePlugin) SetDatabaseHooks(hooks any)
- func (p *BasePlugin) SetEndpointHooks(hooks any)
- func (p *BasePlugin) SetEventHooks(hooks any)
- func (p *BasePlugin) SetInit(fn func(ctx *PluginContext) error)
- func (p *BasePlugin) SetMetadata(meta PluginMetadata)
- func (p *BasePlugin) SetMigrations(migrations []any)
- func (p *BasePlugin) SetRateLimit(rateLimit *PluginRateLimit)
- func (p *BasePlugin) SetRoutes(routes []PluginRoute)
- func (p *BasePlugin) SetWebhooks(hooks any)
- func (p *BasePlugin) Webhooks() any
- type CSRFConfig
- type ChangeEmailConfig
- type Config
- type ConfigManager
- type ConfigOption
- type CustomRoute
- type DatabaseConfig
- type DatabaseHooksConfig
- type EmailChangeRequestResult
- type EmailChangeResult
- type EmailConfig
- type EmailPasswordConfig
- type EmailVerificationConfig
- type EndpointHookContext
- type EndpointHooksConfig
- type Event
- type EventBus
- type EventBusConfig
- type EventEmitter
- type EventHandler
- type EventHooksConfig
- type EventPublisher
- type EventSubscriber
- type Handler
- type IPConfig
- type KeyValueStore
- type Logger
- type LoggerConfig
- type MailerService
- type MeResult
- type Message
- type Mode
- type OAuth2LoginResult
- type OAuth2ProviderConfig
- type OAuth2UserInfo
- type PasswordConfig
- type PasswordResetRequestResult
- type PasswordResetResult
- type PasswordService
- type Plugin
- type PluginConfig
- type PluginContext
- type PluginMetadata
- type PluginOption
- type PluginRateLimit
- type PluginRegistry
- type PluginRoute
- type PluginsConfig
- type ProviderType
- type PubSub
- type RateLimitConfig
- type RateLimitCustomRule
- type RateLimitService
- type RouteHandler
- type RouteMiddleware
- type SecondaryStorage
- type SecondaryStorageConfig
- type SecondaryStorageDatabaseOptions
- type SecondaryStorageMemoryOptions
- type SecondaryStorageType
- type Session
- type SessionConfig
- type SessionDatabaseHooksConfig
- type SessionService
- type SignInResult
- type SignOutResult
- type SignUpResult
- type SocialProvidersConfig
- type SubscriptionID
- type TokenService
- type TrustedOriginsConfig
- type User
- type UserConfig
- type UserDatabaseHooksConfig
- type UserService
- type Verification
- type VerificationDatabaseHooksConfig
- type VerificationService
- type VerificationType
- type VerifyEmailResult
- type WebhookConfig
- type WebhookExecutor
- type WebhooksConfig
Constants ¶
const ( EventUserSignedUp = "user.signed_up" EventUserLoggedIn = "user.logged_in" EventEmailVerified = "user.email_verified" EventPasswordChanged = "user.password_changed" EventEmailChanged = "user.email_changed" )
Built-in event types for the authentication system
const (
RateLimitAlgorithmFixedWindow = "fixed_window"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Account ¶
type Account struct {
ID string `json:"id" gorm:"primaryKey"`
UserID string `json:"user_id" gorm:"index"`
AccountID string `json:"account_id"`
ProviderID ProviderType `json:"provider_id"`
AccessToken *string `json:"access_token,omitempty"`
RefreshToken *string `json:"refresh_token,omitempty"`
IDToken *string `json:"id_token,omitempty"`
AccessTokenExpiresAt *time.Time `json:"access_token_expires_at,omitempty"`
RefreshTokenExpiresAt *time.Time `json:"refresh_token_expires_at,omitempty"`
Scope *string `json:"scope,omitempty"`
Password *string `json:"password,omitempty"` // for email/password auth
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
User User `gorm:"foreignKey:UserID"`
}
type AccountService ¶
type ApiMiddleware ¶ added in v1.4.0
type ApiMiddleware struct {
AdminAuth func() func(http.Handler) http.Handler
Auth func() func(http.Handler) http.Handler
OptionalAuth func() func(http.Handler) http.Handler
CorsAuth func() func(http.Handler) http.Handler
CSRF func() func(http.Handler) http.Handler
RateLimit func() func(http.Handler) http.Handler
EndpointHooks func() func(http.Handler) http.Handler
}
type AuthApi ¶ added in v1.4.0
type AuthApi interface {
Services() *AuthServices
SignUpWithEmailAndPassword(ctx context.Context, name string, email string, password string, callbackURL *string) (*SignUpResult, error)
SignInWithEmailAndPassword(ctx context.Context, email string, password string, callbackURL *string) (*SignInResult, error)
SignOut(ctx context.Context, sessionToken string) error
VerifyEmail(ctx context.Context, rawToken string) (*VerifyEmailResult, error)
SendEmailVerification(ctx context.Context, userID string, callbackURL *string) error
ResetPassword(ctx context.Context, email string, callbackURL *string) error
ChangePassword(ctx context.Context, rawToken string, newPassword string) error
EmailChange(ctx context.Context, userID string, newEmail string, callbackURL *string) error
GetMe(ctx context.Context, userID string) (*MeResult, error)
PrepareOAuth2Login(ctx context.Context, providerName string) (*OAuth2LoginResult, error)
SignInWithOAuth2(ctx context.Context, providerName string, code string, state string, verifier *string) (*SignInResult, error)
}
AuthApi defines the interface for the authentication API
type AuthServices ¶ added in v1.4.0
type AuthServices struct {
Users UserService
Accounts AccountService
Sessions SessionService
Verifications VerificationService
Passwords PasswordService
Tokens TokenService
RateLimits RateLimitService
Mailers MailerService
}
AuthServices groups all service interfaces related to authentication
type AuthSettings ¶ added in v1.4.0
type AuthSettings struct {
// The unique key for the config block (e.g., "runtime_config" for the main config)
Key string `gorm:"primaryKey;type:varchar(255)" json:"key"`
// Value contains the JSON-encoded configuration data
Value json.RawMessage `gorm:"type:jsonb" json:"value"`
// CreatedAt is the timestamp when this setting was created
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
// UpdatedAt is the timestamp when this setting was last updated
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
AuthSettings stores dynamic configuration for the auth system in the database. This is used primarily in database mode to persist the full runtime configuration.
func (AuthSettings) TableName ¶ added in v1.4.0
func (AuthSettings) TableName() string
TableName specifies the table name for the AuthSettings model
type BasePlugin ¶ added in v1.3.4
type BasePlugin struct {
// contains filtered or unexported fields
}
func (*BasePlugin) Close ¶ added in v1.3.4
func (p *BasePlugin) Close() error
func (*BasePlugin) Config ¶ added in v1.3.4
func (p *BasePlugin) Config() PluginConfig
func (*BasePlugin) Ctx ¶ added in v1.3.4
func (p *BasePlugin) Ctx() *PluginContext
func (*BasePlugin) DatabaseHooks ¶ added in v1.3.4
func (p *BasePlugin) DatabaseHooks() any
func (*BasePlugin) EndpointHooks ¶ added in v1.4.0
func (p *BasePlugin) EndpointHooks() any
func (*BasePlugin) EventHooks ¶ added in v1.3.4
func (p *BasePlugin) EventHooks() any
func (*BasePlugin) Init ¶ added in v1.3.4
func (p *BasePlugin) Init(ctx *PluginContext) error
func (*BasePlugin) Metadata ¶ added in v1.3.4
func (p *BasePlugin) Metadata() PluginMetadata
func (*BasePlugin) Migrations ¶ added in v1.3.4
func (p *BasePlugin) Migrations() []any
func (*BasePlugin) RateLimit ¶ added in v1.3.4
func (p *BasePlugin) RateLimit() *PluginRateLimit
func (*BasePlugin) Routes ¶ added in v1.3.4
func (p *BasePlugin) Routes() []PluginRoute
func (*BasePlugin) SetClose ¶ added in v1.3.4
func (p *BasePlugin) SetClose(fn func() error)
func (*BasePlugin) SetConfig ¶ added in v1.3.4
func (p *BasePlugin) SetConfig(config PluginConfig)
func (*BasePlugin) SetCtx ¶ added in v1.3.4
func (p *BasePlugin) SetCtx(ctx *PluginContext)
func (*BasePlugin) SetDatabaseHooks ¶ added in v1.3.4
func (p *BasePlugin) SetDatabaseHooks(hooks any)
func (*BasePlugin) SetEndpointHooks ¶ added in v1.4.0
func (p *BasePlugin) SetEndpointHooks(hooks any)
func (*BasePlugin) SetEventHooks ¶ added in v1.3.4
func (p *BasePlugin) SetEventHooks(hooks any)
func (*BasePlugin) SetInit ¶ added in v1.3.4
func (p *BasePlugin) SetInit(fn func(ctx *PluginContext) error)
func (*BasePlugin) SetMetadata ¶ added in v1.3.4
func (p *BasePlugin) SetMetadata(meta PluginMetadata)
func (*BasePlugin) SetMigrations ¶ added in v1.3.4
func (p *BasePlugin) SetMigrations(migrations []any)
func (*BasePlugin) SetRateLimit ¶ added in v1.3.4
func (p *BasePlugin) SetRateLimit(rateLimit *PluginRateLimit)
func (*BasePlugin) SetRoutes ¶ added in v1.3.4
func (p *BasePlugin) SetRoutes(routes []PluginRoute)
func (*BasePlugin) SetWebhooks ¶ added in v1.4.0
func (p *BasePlugin) SetWebhooks(hooks any)
func (*BasePlugin) Webhooks ¶ added in v1.4.0
func (p *BasePlugin) Webhooks() any
type CSRFConfig ¶
type ChangeEmailConfig ¶
type Config ¶
type Config struct {
Mode Mode `json:"-" toml:"-"`
AppName string `json:"app_name" toml:"app_name"`
BaseURL string `json:"base_url" toml:"base_url"`
BasePath string `json:"base_path" toml:"base_path"`
Secret string `json:"secret" toml:"secret"`
Logger LoggerConfig `json:"logger" toml:"logger"`
DB *gorm.DB `json:"-" toml:"-"`
Database DatabaseConfig `json:"database" toml:"database"`
Email EmailConfig `json:"email" toml:"email"`
SecondaryStorage SecondaryStorageConfig `json:"secondary_storage" toml:"secondary_storage"`
EmailPassword EmailPasswordConfig `json:"email_password" toml:"email_password"`
EmailVerification EmailVerificationConfig `json:"email_verification" toml:"email_verification"`
User UserConfig `json:"user" toml:"user"`
Session SessionConfig `json:"session" toml:"session"`
CSRF CSRFConfig `json:"csrf" toml:"csrf"`
SocialProviders SocialProvidersConfig `json:"social_providers" toml:"social_providers"`
TrustedOrigins TrustedOriginsConfig `json:"trusted_origins" toml:"trusted_origins"`
RateLimit RateLimitConfig `json:"rate_limit" toml:"rate_limit"`
EndpointHooks EndpointHooksConfig `json:"-" toml:"-"`
DatabaseHooks DatabaseHooksConfig `json:"-" toml:"-"`
EventHooks EventHooksConfig `json:"-" toml:"-"`
Webhooks WebhooksConfig `json:"webhooks" toml:"webhooks"`
EventBus EventBusConfig `json:"event_bus" toml:"event_bus"`
Plugins PluginsConfig `json:"-" toml:"-"`
}
Config holds all configurable options for the GoBetterAuth library.
type ConfigManager ¶ added in v1.4.0
type ConfigOption ¶
type ConfigOption func(*Config)
type CustomRoute ¶
type CustomRoute struct {
Method string
Path string
Middleware []RouteMiddleware
Handler RouteHandler
}
type DatabaseConfig ¶
type DatabaseConfig struct {
Provider string `json:"provider" toml:"provider"`
URL string `json:"url" toml:"url"`
MaxOpenConns int `json:"max_open_conns" toml:"max_open_conns"`
MaxIdleConns int `json:"max_idle_conns" toml:"max_idle_conns"`
ConnMaxLifetime time.Duration `json:"conn_max_lifetime" toml:"conn_max_lifetime"`
}
type DatabaseHooksConfig ¶
type DatabaseHooksConfig struct {
Users *UserDatabaseHooksConfig
Accounts *AccountDatabaseHooksConfig
Sessions *SessionDatabaseHooksConfig
Verifications *VerificationDatabaseHooksConfig
}
type EmailChangeRequestResult ¶ added in v1.4.0
type EmailChangeRequestResult struct {
Message string `json:"message"`
}
EmailChangeRequestResult represents the result of an email change request
type EmailChangeResult ¶ added in v1.4.0
type EmailChangeResult struct {
Message string `json:"message"`
User *User `json:"user,omitempty"`
}
EmailChangeResult represents the result of confirming an email change
type EmailConfig ¶ added in v1.4.0
type EmailConfig struct {
Provider string `json:"provider" toml:"provider"`
SMTPHost string `json:"smtp_host" toml:"smtp_host"`
SMTPPort int `json:"smtp_port" toml:"smtp_port"`
SMTPUser string `json:"smtp_user" toml:"smtp_user"`
SMTPPass string `json:"smtp_pass" toml:"smtp_pass"`
From string `json:"from" toml:"from"`
}
type EmailPasswordConfig ¶
type EmailPasswordConfig struct {
Enabled bool `json:"enabled" toml:"enabled"`
MinPasswordLength int `json:"min_password_length" toml:"min_password_length"`
MaxPasswordLength int `json:"max_password_length" toml:"max_password_length"`
DisableSignUp bool `json:"disable_sign_up" toml:"disable_sign_up"`
RequireEmailVerification bool `json:"require_email_verification" toml:"require_email_verification"`
AutoSignIn bool `json:"auto_sign_in" toml:"auto_sign_in"`
ResetTokenExpiry time.Duration `json:"reset_token_expiry" toml:"reset_token_expiry"`
// Library mode only
Password PasswordConfig `json:"-" toml:"-"`
SendResetPasswordEmail func(user User, url string, token string) error `json:"-" toml:"-"`
}
type EmailVerificationConfig ¶
type EmailVerificationConfig struct {
AutoSignIn bool `json:"auto_sign_in" toml:"auto_sign_in"`
SendOnSignUp bool `json:"send_on_sign_up" toml:"send_on_sign_up"`
SendOnSignIn bool `json:"send_on_sign_in" toml:"send_on_sign_in"`
ExpiresIn time.Duration `json:"expires_in" toml:"expires_in"`
// Library mode only
SendVerificationEmail func(user User, url string, token string) error `json:"-" toml:"-"`
}
type EndpointHookContext ¶
type EndpointHookContext struct {
Path string
Method string
Body map[string]any
Headers map[string][]string
Query map[string][]string
Request *http.Request
User *User
ResponseStatus int
ResponseHeaders map[string][]string
ResponseBody []byte
ResponseCookies []*http.Cookie
Redirect func(url string, status int)
Handled bool
}
type EndpointHooksConfig ¶
type EndpointHooksConfig struct {
Before func(ctx *EndpointHookContext) error
Response func(ctx *EndpointHookContext) error
After func(ctx *EndpointHookContext)
}
type Event ¶
type Event struct {
ID string `json:"id"`
Type string `json:"type"`
Timestamp time.Time `json:"timestamp"`
Payload json.RawMessage `json:"payload"`
Metadata map[string]string `json:"metadata"`
}
Event represents data to be published or received via the EventBus
type EventBus ¶
type EventBus interface {
EventPublisher
EventSubscriber
}
EventBus combines publisher and subscriber functionality
type EventBusConfig ¶
type EventBusConfig struct {
Enabled bool `json:"enabled" toml:"enabled"`
Prefix string `json:"prefix" toml:"prefix"`
MaxConcurrentHandlers int `json:"max_concurrent_handlers" toml:"max_concurrent_handlers"`
PubSubType string `json:"pubsub_type" toml:"pubsub_type"`
PubSub PubSub `json:"-" toml:"-"`
}
type EventEmitter ¶ added in v1.4.0
type EventHandler ¶
EventHandler processes events
type EventHooksConfig ¶
type EventPublisher ¶
EventPublisher defines the interface for publishing events
type EventSubscriber ¶
type EventSubscriber interface {
Subscribe(eventType string, handler EventHandler) (SubscriptionID, error)
Unsubscribe(eventType string, id SubscriptionID)
Close() error
}
EventSubscriber defines the interface for subscribing to events
type Handler ¶ added in v1.5.2
type Handler interface {
Handle(w http.ResponseWriter, r *http.Request)
}
Handler is the interface for creating HTTP handlers for routes.
type KeyValueStore ¶
type KeyValueStore struct {
Key string `gorm:"primaryKey;type:varchar(255)" json:"key" `
Value string `json:"value"`
ExpiresAt *time.Time `json:"expires_at,omitempty"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
KeyValueStore represents the persistent key-value store table in the database. This is a domain model used for secondary storage operations.
func (KeyValueStore) TableName ¶ added in v1.4.0
func (KeyValueStore) TableName() string
TableName overrides the table name for GORM
type Logger ¶ added in v1.4.0
type Logger interface {
// Debug logs a message at debug level with optional key-value pairs.
Debug(msg string, args ...any)
// Info logs a message at info level with optional key-value pairs.
Info(msg string, args ...any)
// Warn logs a message at warn level with optional key-value pairs.
Warn(msg string, args ...any)
// Error logs a message at error level with optional key-value pairs.
Error(msg string, args ...any)
}
Logger defines an interface for logging operations, allowing users to plug in different logging implementations such as slog, zerolog, or others.
type LoggerConfig ¶ added in v1.4.0
type MailerService ¶ added in v1.4.0
type Message ¶
type Message struct {
UUID string
Payload []byte // Message payload (serialized data)
Metadata map[string]string
}
Message represents a message in the pub/sub system.
type OAuth2LoginResult ¶ added in v1.4.0
type OAuth2LoginResult struct {
AuthURL string // The authorization URL to redirect to
State string // CSRF protection state
Verifier *string // PKCE code verifier (if PKCE is required)
}
OAuth2LoginResult contains the information needed for the OAuth2 login flow
type OAuth2ProviderConfig ¶ added in v1.4.0
type OAuth2ProviderConfig struct {
Enabled bool `json:"enabled" toml:"enabled"`
ClientID string `json:"client_id" toml:"client_id"`
ClientSecret string `json:"client_secret" toml:"client_secret"`
RedirectURL string `json:"redirect_url" toml:"redirect_url"`
Scopes []string `json:"scopes" toml:"scopes"`
// For generic providers or overriding defaults
AuthURL string `json:"auth_url" toml:"auth_url"`
TokenURL string `json:"token_url" toml:"token_url"`
UserInfoURL string `json:"user_info_url" toml:"user_info_url"`
}
type OAuth2UserInfo ¶
type PasswordConfig ¶
type PasswordConfig struct {
Hash func(password string) (string, error) `json:"-" toml:"-"`
Verify func(hashedPassword, password string) bool `json:"-" toml:"-"`
}
Library mode only
type PasswordResetRequestResult ¶ added in v1.4.0
type PasswordResetRequestResult struct {
Message string `json:"message"`
}
PasswordResetRequestResult represents the result of a password reset request
type PasswordResetResult ¶ added in v1.4.0
type PasswordResetResult struct {
Message string `json:"message"`
}
PasswordResetResult represents the result of a password reset
type PasswordService ¶ added in v1.4.0
type Plugin ¶
type Plugin interface {
Metadata() PluginMetadata
SetMetadata(meta PluginMetadata)
Config() PluginConfig
SetConfig(cfg PluginConfig)
Ctx() *PluginContext
SetCtx(ctx *PluginContext)
Init(ctx *PluginContext) error
SetInit(fn func(ctx *PluginContext) error)
Migrations() []any
SetMigrations(migrations []any)
Routes() []PluginRoute
SetRoutes(routes []PluginRoute)
RateLimit() *PluginRateLimit
SetRateLimit(rateLimit *PluginRateLimit)
EndpointHooks() any
SetEndpointHooks(hooks any)
DatabaseHooks() any
SetDatabaseHooks(hooks any)
EventHooks() any
SetEventHooks(hooks any)
Webhooks() any
SetWebhooks(hooks any)
Close() error
SetClose(fn func() error)
}
type PluginConfig ¶
PluginConfig holds per-plugin configuration.
type PluginContext ¶
type PluginContext struct {
Config *Config
Api AuthApi
EventBus EventBus
Middleware *ApiMiddleware
WebhookExecutor WebhookExecutor
Plugin Plugin // Reference to the plugin being initialized
}
type PluginMetadata ¶
type PluginOption ¶ added in v1.3.4
type PluginOption func(p Plugin)
type PluginRateLimit ¶
type PluginRateLimit = RateLimitConfig
type PluginRegistry ¶ added in v1.4.0
type PluginRoute ¶
type PluginRoute struct {
Method string
Path string // Relative path, /auth is auto-prefixed
Middleware []RouteMiddleware
Handler RouteHandler
}
type ProviderType ¶
type ProviderType string
const ( ProviderEmail ProviderType = "email" ProviderDiscord ProviderType = "discord" ProviderGitHub ProviderType = "github" ProviderGoogle ProviderType = "google" )
type PubSub ¶
type PubSub interface {
// Publish sends a message to the specified topic
Publish(ctx context.Context, topic string, msg *Message) error
// Subscribe returns a channel that receives messages from the specified topic.
// The channel should be closed when the subscription is cancelled or closed.
Subscribe(ctx context.Context, topic string) (<-chan *Message, error)
// Close closes the pub/sub and cleans up resources
Close() error
}
PubSub is a generic publish-subscribe interface.
type RateLimitConfig ¶
type RateLimitConfig struct {
Enabled bool `json:"enabled" toml:"enabled"`
Window time.Duration `json:"window" toml:"window"`
Max int `json:"max" toml:"max"`
Algorithm string `json:"algorithm" toml:"algorithm"`
Prefix string `json:"prefix" toml:"prefix"`
CustomRules map[string]RateLimitCustomRule `json:"custom_rules" toml:"custom_rules"`
IP IPConfig `json:"ip" toml:"ip"`
}
type RateLimitCustomRule ¶
type RateLimitService ¶
type RouteHandler ¶ added in v1.5.2
func WrapHandler ¶ added in v1.5.2
func WrapHandler(h Handler) RouteHandler
WrapHandler converts a Handler to a RouteHandler.
type SecondaryStorage ¶
type SecondaryStorage interface {
Get(ctx context.Context, key string) (any, error)
Set(ctx context.Context, key string, value any, ttl *time.Duration) error
Delete(ctx context.Context, key string) error
Incr(ctx context.Context, key string, ttl *time.Duration) (int, error)
Close() error
}
SecondaryStorage defines an interface for secondary storage operations.
type SecondaryStorageConfig ¶
type SecondaryStorageConfig struct {
Type SecondaryStorageType `json:"type" toml:"type"`
MemoryOptions SecondaryStorageMemoryOptions `json:"memory_options" toml:"memory_options"`
DatabaseOptions SecondaryStorageDatabaseOptions `json:"database_options" toml:"database_options"`
Storage SecondaryStorage `json:"-" toml:"-"`
}
type SecondaryStorageType ¶
type SecondaryStorageType string
const ( SecondaryStorageTypeMemory SecondaryStorageType = "memory" SecondaryStorageTypeDatabase SecondaryStorageType = "database" SecondaryStorageTypeCustom SecondaryStorageType = "custom" )
type Session ¶
type Session struct {
ID string `json:"id" gorm:"primaryKey"`
UserID string `json:"user_id" gorm:"index"`
Token string `json:"token" gorm:"uniqueIndex"`
ExpiresAt time.Time `json:"expires_at"`
IPAddress *string `json:"ip_address,omitempty"`
UserAgent *string `json:"user_agent,omitempty"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
type SessionConfig ¶
type SessionService ¶
type SignInResult ¶ added in v1.4.0
type SignInResult struct {
Token string `json:"token"`
User *User `json:"user"`
CSRFToken *string `json:"csrf_token,omitempty"`
}
SignInResult represents the result of a sign-in operation
type SignOutResult ¶ added in v1.4.0
type SignOutResult struct {
Message string `json:"message"`
}
SignOutResult represents the result of a sign-out operation
type SignUpResult ¶ added in v1.4.0
type SignUpResult struct {
Token string `json:"token,omitempty"`
User *User `json:"user"`
CSRFToken *string `json:"csrf_token,omitempty"`
}
SignUpResult represents the result of a sign-up operation
type SocialProvidersConfig ¶
type SocialProvidersConfig map[string]OAuth2ProviderConfig
type SubscriptionID ¶ added in v1.3.1
type SubscriptionID uint64
SubscriptionID identifies a specific event handler subscription for removal
type TokenService ¶
type TrustedOriginsConfig ¶
type TrustedOriginsConfig struct {
Origins []string `json:"origins" toml:"origins"`
}
type User ¶
type User struct {
ID string `json:"id" gorm:"primaryKey"`
Name string `json:"name"`
Email string `json:"email" gorm:"uniqueIndex"`
EmailVerified bool `json:"email_verified"`
Image *string `json:"image,omitempty"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
type UserConfig ¶
type UserConfig struct {
ChangeEmail ChangeEmailConfig `json:"change_email" toml:"change_email"`
}
type UserDatabaseHooksConfig ¶
type UserService ¶
type Verification ¶
type Verification struct {
ID string `json:"id" gorm:"primaryKey"`
UserID *string `json:"user_id,omitempty"`
Identifier string `json:"identifier"` // email or other identifier
Token string `json:"token"`
Type VerificationType `json:"type"`
ExpiresAt time.Time `json:"expires_at"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
type VerificationDatabaseHooksConfig ¶
type VerificationDatabaseHooksConfig struct {
BeforeCreate func(verification *Verification) error
AfterCreate func(verification Verification) error
}
type VerificationService ¶
type VerificationService interface {
CreateVerification(verif *Verification) error
GetVerificationByToken(token string) (*Verification, error)
DeleteVerification(id string) error
IsExpired(verif *Verification) bool
}
type VerificationType ¶
type VerificationType string
const ( TypeEmailVerification VerificationType = "email_verification" TypePasswordReset VerificationType = "password_reset" TypeEmailChange VerificationType = "email_change" )
type VerifyEmailResult ¶ added in v1.4.0
type VerifyEmailResult struct {
Message string `json:"message"`
User *User `json:"user,omitempty"`
}
VerifyEmailResult represents the result of email verification
type WebhookConfig ¶ added in v1.4.0
type WebhookExecutor ¶ added in v1.4.0
type WebhookExecutor interface {
ExecuteWebhook(webhook *WebhookConfig, payload any) error
}
WebhookExecutor defines the interface for executing webhooks
type WebhooksConfig ¶ added in v1.4.0
type WebhooksConfig struct {
OnUserSignedUp *WebhookConfig `json:"on_user_signed_up" toml:"on_user_signed_up"`
OnUserLoggedIn *WebhookConfig `json:"on_user_logged_in" toml:"on_user_logged_in"`
OnEmailVerified *WebhookConfig `json:"on_email_verified" toml:"on_email_verified"`
OnPasswordChanged *WebhookConfig `json:"on_password_changed" toml:"on_password_changed"`
OnEmailChanged *WebhookConfig `json:"on_email_changed" toml:"on_email_changed"`
}