postgres

package module
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: MIT Imports: 7 Imported by: 0

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

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 NewAdapter(db *sql.DB) *Adapter

func (*Adapter) CleanupExpiredSessions

func (a *Adapter) CleanupExpiredSessions(ctx context.Context) error

CleanupExpiredSessions removes sessions that have passed their expiration time.

func (*Adapter) CreateSession

func (a *Adapter) CreateSession(ctx context.Context, session *authingo.Session) error

CreateSession stores a new login session token in the database.

func (*Adapter) CreateUser

func (a *Adapter) CreateUser(ctx context.Context, user *authingo.User) error

CreateUser inserts a new user record into the database.

func (*Adapter) DeleteSession

func (a *Adapter) DeleteSession(ctx context.Context, token string) error

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

func (a *Adapter) GetUserByEmail(ctx context.Context, email string) (*authingo.User, error)

GetUserByEmail retrieves a user by their email address.

func (*Adapter) RefreshSession

func (a *Adapter) RefreshSession(ctx context.Context, oldToken string) (*authingo.Session, *authingo.User, error)

RefreshSession updates the session's expiration time (used for "remember me" functionality).

Jump to

Keyboard shortcuts

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