Documentation
¶
Overview ¶
Package postgres provides a PostgreSQL storage adapter for the AuthInGo framework.
It implements the authingo.Store interface, allowing the core authentication engine to persist users and active sessions securely in a PostgreSQL database. This adapter is built on top of the standard database/sql library and is optimized for the "pgx" driver.
Key Features:
- Complete Repository Implementation: Manages both User and Session lifecycles.
- Automated Garbage Collection: Fully supports AuthInGo's CleanupExpiredSessions method to automatically scrub dead refresh tokens and prevent database bloat.
- Context-Aware: All database operations support context.Context for robust timeouts and query cancellations.
Usage:
db, _ := sql.Open("pgx", "postgres://user:pass@localhost:5432/mydb")
auth := authingo.New(authingo.Options{
Store: postgres.NewAdapter(db),
})
Index ¶
- type Adapter
- func (a *Adapter) CleanupExpiredSessions(ctx context.Context) error
- func (a *Adapter) CreateSession(ctx context.Context, session *authingo.Session) error
- func (a *Adapter) CreateUser(ctx context.Context, user *authingo.User) error
- func (a *Adapter) DeleteSession(ctx context.Context, token string) error
- func (a *Adapter) GetSession(ctx context.Context, token string) (*authingo.Session, *authingo.User, error)
- func (a *Adapter) GetUserByEmail(ctx context.Context, email string) (*authingo.User, error)
- func (a *Adapter) RefreshSession(ctx context.Context, oldToken string) (*authingo.Session, *authingo.User, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Adapter ¶
type Adapter struct {
// contains filtered or unexported fields
}
func NewAdapter ¶
func (*Adapter) CleanupExpiredSessions ¶
CleanupExpiredSessions removes sessions that have passed their expiration time.
func (*Adapter) CreateSession ¶
CreateSession stores a new login session token in the database.
func (*Adapter) CreateUser ¶
CreateUser inserts a new user record into the database.
func (*Adapter) DeleteSession ¶
DeleteSession removes a session from the database (used for logout).
func (*Adapter) GetSession ¶
func (a *Adapter) GetSession(ctx context.Context, token string) (*authingo.Session, *authingo.User, error)
GetSession retrieves a session and its associated user via a SQL JOIN.
func (*Adapter) GetUserByEmail ¶
GetUserByEmail retrieves a user by their email address.