hook

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 10, 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 APIKeyEvent added in v0.3.0

type APIKeyEvent struct {
	Key  *store.APIKey
	User *store.User
	Tx   store.Store
}

APIKeyEvent carries a created or a revoked API key. The plaintext key is never part of it.

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

AccountLink carries a completed external account link.

type AfterAPIKeyCreateFunc added in v0.3.0

type AfterAPIKeyCreateFunc func(ctx context.Context, ev *APIKeyEvent) error

AfterAPIKeyCreateFunc runs after commit.

type AfterAPIKeyRevokeFunc added in v0.3.0

type AfterAPIKeyRevokeFunc func(ctx context.Context, ev *APIKeyEvent) error

AfterAPIKeyRevokeFunc runs after commit.

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 AfterRoleChangeFunc added in v0.3.0

type AfterRoleChangeFunc func(ctx context.Context, ev *RoleChange) error

AfterRoleChangeFunc 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 AfterUserUpdateFunc added in v0.3.0

type AfterUserUpdateFunc func(ctx context.Context, ev *UserUpdate) error

AfterUserUpdateFunc runs after commit.

type BeforeRoleChangeFunc added in v0.3.0

type BeforeRoleChangeFunc func(ctx context.Context, ev *RoleChange) error

BeforeRoleChangeFunc runs in the transaction and can reject.

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 BeforeUserUpdateFunc added in v0.3.0

type BeforeUserUpdateFunc func(ctx context.Context, ev *UserUpdate) error

BeforeUserUpdateFunc 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 (*Hooks) OnAfterAPIKeyCreate added in v0.3.0

func (h *Hooks) OnAfterAPIKeyCreate(fn AfterAPIKeyCreateFunc)

OnAfterAPIKeyCreate registers a hook that runs after commit.

func (*Hooks) OnAfterAPIKeyRevoke added in v0.3.0

func (h *Hooks) OnAfterAPIKeyRevoke(fn AfterAPIKeyRevokeFunc)

OnAfterAPIKeyRevoke registers a hook that runs after commit.

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) OnAfterRoleChange added in v0.3.0

func (h *Hooks) OnAfterRoleChange(fn AfterRoleChangeFunc)

OnAfterRoleChange 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) OnAfterUserUpdate added in v0.3.0

func (h *Hooks) OnAfterUserUpdate(fn AfterUserUpdateFunc)

OnAfterUserUpdate registers a hook that runs after commit.

func (*Hooks) OnBeforeRoleChange added in v0.3.0

func (h *Hooks) OnBeforeRoleChange(fn BeforeRoleChangeFunc)

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

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 (*Hooks) OnBeforeUserUpdate added in v0.3.0

func (h *Hooks) OnBeforeUserUpdate(fn BeforeUserUpdateFunc)

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

func (*Hooks) RunAfterAPIKeyCreate added in v0.3.0

func (h *Hooks) RunAfterAPIKeyCreate(ctx context.Context, ev *APIKeyEvent)

RunAfterAPIKeyCreate runs the registered hooks after commit.

func (*Hooks) RunAfterAPIKeyRevoke added in v0.3.0

func (h *Hooks) RunAfterAPIKeyRevoke(ctx context.Context, ev *APIKeyEvent)

RunAfterAPIKeyRevoke runs the registered hooks after commit.

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) RunAfterRoleChange added in v0.3.0

func (h *Hooks) RunAfterRoleChange(ctx context.Context, ev *RoleChange)

RunAfterRoleChange 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) RunAfterUserUpdate added in v0.3.0

func (h *Hooks) RunAfterUserUpdate(ctx context.Context, ev *UserUpdate)

RunAfterUserUpdate runs the registered hooks after commit.

func (*Hooks) RunBeforeRoleChange added in v0.3.0

func (h *Hooks) RunBeforeRoleChange(ctx context.Context, ev *RoleChange) error

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

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.

func (*Hooks) RunBeforeUserUpdate added in v0.3.0

func (h *Hooks) RunBeforeUserUpdate(ctx context.Context, ev *UserUpdate) error

RunBeforeUserUpdate 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 RoleChange added in v0.3.0

type RoleChange struct {
	User *store.User
	// From is the role before the change.
	From string
	// To is the role after the change.
	To string
	Tx store.Store
}

RoleChange carries a role change of one user.

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

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.

type UserUpdate added in v0.3.0

type UserUpdate struct {
	User   *store.User
	Before *store.User
	Tx     store.Store
}

UserUpdate carries a user change.

Before holds the user as it was, and User holds the user after the change. A Before hook can change User, and it can reject the operation.

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