hook

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package hook defines the typed lifecycle hooks of Auth-All.

Hook semantics:

  • A Before hook runs inside the database transaction of the operation. It can reject the operation by returning an error.
  • An After hook runs after the transaction commits. It cannot reject the operation. An error from an After hook is reported to the logger.

Auth-All never keeps a database transaction open while it calls an external system, so arbitrary side effects belong in an After hook.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccountLink struct {
	User    *store.User
	Account *store.Account
}

AccountLink carries a completed external account link.

type AfterAccountLinkFunc

type AfterAccountLinkFunc func(ctx context.Context, ev *AccountLink) error

AfterAccountLinkFunc runs after commit.

type AfterPasswordChangeFunc

type AfterPasswordChangeFunc func(ctx context.Context, ev *PasswordChange) error

AfterPasswordChangeFunc runs after commit.

type AfterSessionCreateFunc

type AfterSessionCreateFunc func(ctx context.Context, ev *SessionCreate) error

AfterSessionCreateFunc runs after commit.

type AfterSignInFunc

type AfterSignInFunc func(ctx context.Context, ev *SignIn) error

AfterSignInFunc runs after commit.

type AfterSignOutFunc

type AfterSignOutFunc func(ctx context.Context, ev *SignOut) error

AfterSignOutFunc runs after commit.

type AfterUserCreateFunc

type AfterUserCreateFunc func(ctx context.Context, ev *UserCreate) error

AfterUserCreateFunc runs after commit.

type BeforeSessionCreateFunc

type BeforeSessionCreateFunc func(ctx context.Context, ev *SessionCreate) error

BeforeSessionCreateFunc runs in the transaction and can reject.

type BeforeUserCreateFunc

type BeforeUserCreateFunc func(ctx context.Context, ev *UserCreate) error

BeforeUserCreateFunc runs in the transaction and can reject.

type Hooks

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

Hooks holds every registered lifecycle hook.

func New

func New(onError func(ctx context.Context, name string, err error)) *Hooks

New returns an empty hook set. onError reports an error from an After hook.

func (h *Hooks) OnAfterAccountLink(fn AfterAccountLinkFunc)

OnAfterAccountLink registers a hook that runs after commit.

func (*Hooks) OnAfterPasswordChange

func (h *Hooks) OnAfterPasswordChange(fn AfterPasswordChangeFunc)

OnAfterPasswordChange registers a hook that runs after commit.

func (*Hooks) OnAfterSessionCreate

func (h *Hooks) OnAfterSessionCreate(fn AfterSessionCreateFunc)

OnAfterSessionCreate registers a hook that runs after commit.

func (*Hooks) OnAfterSignIn

func (h *Hooks) OnAfterSignIn(fn AfterSignInFunc)

OnAfterSignIn registers a hook that runs after commit.

func (*Hooks) OnAfterSignOut

func (h *Hooks) OnAfterSignOut(fn AfterSignOutFunc)

OnAfterSignOut registers a hook that runs after commit.

func (*Hooks) OnAfterUserCreate

func (h *Hooks) OnAfterUserCreate(fn AfterUserCreateFunc)

OnAfterUserCreate registers a hook that runs after commit.

func (*Hooks) OnBeforeSessionCreate

func (h *Hooks) OnBeforeSessionCreate(fn BeforeSessionCreateFunc)

OnBeforeSessionCreate registers a hook that runs in the transaction and can reject.

func (*Hooks) OnBeforeUserCreate

func (h *Hooks) OnBeforeUserCreate(fn BeforeUserCreateFunc)

OnBeforeUserCreate registers a hook that runs in the transaction and can reject.

func (h *Hooks) RunAfterAccountLink(ctx context.Context, ev *AccountLink)

RunAfterAccountLink runs the registered hooks after commit.

func (*Hooks) RunAfterPasswordChange

func (h *Hooks) RunAfterPasswordChange(ctx context.Context, ev *PasswordChange)

RunAfterPasswordChange runs the registered hooks after commit.

func (*Hooks) RunAfterSessionCreate

func (h *Hooks) RunAfterSessionCreate(ctx context.Context, ev *SessionCreate)

RunAfterSessionCreate runs the registered hooks after commit.

func (*Hooks) RunAfterSignIn

func (h *Hooks) RunAfterSignIn(ctx context.Context, ev *SignIn)

RunAfterSignIn runs the registered hooks after commit.

func (*Hooks) RunAfterSignOut

func (h *Hooks) RunAfterSignOut(ctx context.Context, ev *SignOut)

RunAfterSignOut runs the registered hooks after commit.

func (*Hooks) RunAfterUserCreate

func (h *Hooks) RunAfterUserCreate(ctx context.Context, ev *UserCreate)

RunAfterUserCreate runs the registered hooks after commit.

func (*Hooks) RunBeforeSessionCreate

func (h *Hooks) RunBeforeSessionCreate(ctx context.Context, ev *SessionCreate) error

RunBeforeSessionCreate runs the registered hooks and stops at the first error.

func (*Hooks) RunBeforeUserCreate

func (h *Hooks) RunBeforeUserCreate(ctx context.Context, ev *UserCreate) error

RunBeforeUserCreate runs the registered hooks and stops at the first error.

type PasswordChange

type PasswordChange struct {
	User *store.User
}

PasswordChange carries a completed password change.

type SessionCreate

type SessionCreate struct {
	Session *store.Session
	User    *store.User
	Tx      store.Store
}

SessionCreate carries a session creation.

type SignIn

type SignIn struct {
	User    *store.User
	Session *store.Session
	Method  string
}

SignIn carries a completed sign-in. Method names the authentication method, for example "email", "magic-link", or a provider id.

type SignOut

type SignOut struct {
	UserID    string
	SessionID string
}

SignOut carries a completed sign-out.

type UserCreate

type UserCreate struct {
	User *store.User
	Tx   store.Store
}

UserCreate carries a user creation.

Tx is the transactional store in a Before hook. Tx is nil in an After hook.

Jump to

Keyboard shortcuts

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