domain

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

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"`
	UpdatedAt             time.Time    `json:"updated_at"`
	User                  User         `gorm:"foreignKey:UserID"`
}

type AccountDatabaseHooksConfig

type AccountDatabaseHooksConfig struct {
	BeforeCreate func(account *Account) error
	AfterCreate  func(account *Account) error
	BeforeUpdate func(account *Account) error
	AfterUpdate  func(account *Account) error
}

type ChangeEmailConfig

type ChangeEmailConfig struct {
	Enabled                     bool
	SendEmailChangeVerification func(user *User, newEmail string, url string, token string) error
}

type Config

type Config struct {
	AppName           string
	BaseURL           string
	BasePath          string
	Secret            string
	Database          DatabaseConfig
	EmailPassword     EmailPasswordConfig
	EmailVerification EmailVerificationConfig
	User              UserConfig
	Session           SessionConfig
	TrustedOrigins    TrustedOriginsConfig
	DatabaseHooks     DatabaseHooksConfig
	Hooks             HooksConfig
}

Config holds all configurable options for the GoBetterAuth library.

func NewConfig

func NewConfig() *Config

NewConfig builds a Config using functional options.

func (*Config) WithAppName

func (c *Config) WithAppName(name string) *Config

func (*Config) WithBasePath

func (c *Config) WithBasePath(path string) *Config

func (*Config) WithBaseURL

func (c *Config) WithBaseURL(url string) *Config

func (*Config) WithDatabase

func (c *Config) WithDatabase(db DatabaseConfig) *Config

func (*Config) WithDatabaseHooks

func (c *Config) WithDatabaseHooks(databaseHooksConfig DatabaseHooksConfig) *Config

func (*Config) WithEmailPassword

func (c *Config) WithEmailPassword(config EmailPasswordConfig) *Config

func (*Config) WithEmailVerification

func (c *Config) WithEmailVerification(config EmailVerificationConfig) *Config

func (*Config) WithHooks

func (c *Config) WithHooks(hooksConfig HooksConfig) *Config

func (*Config) WithSecret

func (c *Config) WithSecret(secret string) *Config

func (*Config) WithSession

func (c *Config) WithSession(sessionConfig SessionConfig) *Config

func (*Config) WithTrustedOrigins

func (c *Config) WithTrustedOrigins(trustedOriginsConfig TrustedOriginsConfig) *Config

func (*Config) WithUser

func (c *Config) WithUser(userConfig UserConfig) *Config

type DatabaseConfig

type DatabaseConfig struct {
	Provider         string
	ConnectionString string
	MaxOpenConns     int
	MaxIdleConns     int
	ConnMaxLifetime  time.Duration
}

type DatabaseHooksConfig

type DatabaseHooksConfig struct {
	Users         *UserDatabaseHooksConfig
	Accounts      *AccountDatabaseHooksConfig
	Sessions      *SessionDatabaseHooksConfig
	Verifications *VerificationDatabaseHooksConfig
}

type EmailPasswordConfig

type EmailPasswordConfig struct {
	Enabled                  bool
	MinPasswordLength        int
	MaxPasswordLength        int
	DisableSignUp            bool
	RequireEmailVerification bool
	AutoSignIn               bool
	SendResetPassword        func(user *User, url string, token string) error
	ResetTokenExpiry         time.Duration
	Password                 *PasswordConfig
}

type EmailVerificationConfig

type EmailVerificationConfig struct {
	SendVerificationEmail func(user *User, url string, token string) error
	AutoSignIn            bool
	SendOnSignUp          bool
	SendOnSignIn          bool
	ExpiresIn             time.Duration
}

type HooksConfig

type HooksConfig struct {
	OnUserSignedUp    func(user User) error
	OnUserLoggedIn    func(user User) error
	OnEmailVerified   func(user User) error
	OnEmailChanged    func(user User) error
	OnPasswordChanged func(user User) error
}

type PasswordConfig

type PasswordConfig struct {
	Hash   func(password string) (string, error)
	Verify func(hashedPassword, password string) bool
}

type ProviderType

type ProviderType string
const (
	ProviderEmail   ProviderType = "email"
	ProviderGoogle  ProviderType = "google"
	ProviderGitHub  ProviderType = "github"
	ProviderDiscord ProviderType = "discord"
)

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"`
	UpdatedAt time.Time `json:"updated_at"`
}

type SessionConfig

type SessionConfig struct {
	ExpiresIn  time.Duration
	UpdateAge  time.Duration
	CookieName string
}

type SessionDatabaseHooksConfig

type SessionDatabaseHooksConfig struct {
	BeforeCreate func(session *Session) error
	AfterCreate  func(session *Session) error
	BeforeUpdate func(session *Session) error
	AfterUpdate  func(session *Session) error
}

type TrustedOriginsConfig

type TrustedOriginsConfig struct {
	Origins []string
}

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"`
	UpdatedAt     time.Time `json:"updated_at"`
}

type UserConfig

type UserConfig struct {
	ChangeEmail ChangeEmailConfig
}

type UserDatabaseHooksConfig

type UserDatabaseHooksConfig struct {
	BeforeCreate func(user *User) error
	AfterCreate  func(user *User) error
	BeforeUpdate func(user *User) error
	AfterUpdate  func(user *User) error
}

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"`
	UpdatedAt  time.Time        `json:"updated_at"`
}

type VerificationDatabaseHooksConfig

type VerificationDatabaseHooksConfig struct {
	BeforeCreate func(verification *Verification) error
	AfterCreate  func(verification *Verification) error
}

type VerificationType

type VerificationType string
const (
	TypeEmailVerification VerificationType = "email_verification"
	TypePasswordReset     VerificationType = "password_reset"
	TypeEmailChange       VerificationType = "email_change"
)

Jump to

Keyboard shortcuts

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