stores

package
v1.4.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// User-related errors
	ErrUserExists      = errors.New("user already exists")
	ErrUserNotFound    = errors.New("user not found")
	ErrInvalidPassword = errors.New("invalid password for user")

	// store errors
	ErrStoreNotProvided = errors.New("store must be provided")
)

Functions

This section is empty.

Types

type AuthifyDB

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

func NewAuthifyDB

func NewAuthifyDB(connString string, cfg StoreConfig) (*AuthifyDB, error)

This function takes in a connection string and a table name. It initializes a connection with the database, and sets its context as context.Background() After that, it attempts to create table if it does not exist with the passed tablename and config in the store.yml file. Documentation for pgx package: https://pkg.go.dev/github.com/jackc/pgx/v5

func (*AuthifyDB) CreateUser

func (db *AuthifyDB) CreateUser(data map[string]any) error

This function takes in username and password It creates the username with hashed password and provided information, as per config in database Noteworthy that the cost passed to GenerateFromPassword function is the default cost (10) Documentation for bcrypt: https://pkg.go.dev/golang.org/x/crypto/bcrypt

func (*AuthifyDB) GetUserInfo

func (db *AuthifyDB) GetUserInfo(userIdentifier, password string) (map[string]any, error)

This function takes in the user identifier and password and returns info of user after password validation uses bcrypt's CompareHashAndPassword function for password validation

func (*AuthifyDB) StoreConfig

func (db *AuthifyDB) StoreConfig() StoreConfig

type ColumnConfig

type ColumnConfig struct {
	Type       string `yaml:"type"`
	PrimaryKey bool   `yaml:"primary_key"`
	Unique     bool   `yaml:"unique"`
	Required   bool   `yaml:"required"`
	Default    string `yaml:"default"`
	Hidden     bool   `yaml:"hidden"`
	IsPassword bool   `yaml:"is_password"`
	JWTClaim   string `yaml:"jwt_claim"`
}

type InMemoryUserStore

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

InMemoryUserStore is a config-driven, in-memory implementation of Store

func NewInMemoryUserStore

func NewInMemoryUserStore(cfg StoreConfig) *InMemoryUserStore

NewInMemoryUserStore initializes a new in-memory store using table config

func (*InMemoryUserStore) CreateUser

func (m *InMemoryUserStore) CreateUser(data map[string]any) error

CreateUser creates a user using dynamic fields defined in config

func (*InMemoryUserStore) GetUserInfo

func (m *InMemoryUserStore) GetUserInfo(username, password string) (map[string]any, error)

GetUserInfo authenticates and returns non-hidden user fields

func (*InMemoryUserStore) StoreConfig

func (m *InMemoryUserStore) StoreConfig() StoreConfig

StoreConfig exposes the schema config

type Store

type Store interface {
	CreateUser(data map[string]any) error
	GetUserInfo(userIdentifier, password string) (map[string]any, error)
	StoreConfig() StoreConfig
}

type StoreConfig

type StoreConfig struct {
	Name       string                  `yaml:"name"`
	AutoCreate bool                    `yaml:"auto_create"`
	Columns    map[string]ColumnConfig `yaml:"columns"`
}

Jump to

Keyboard shortcuts

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