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 ¶
- type APIKeyEvent
- type AccountLink
- type AfterAPIKeyCreateFunc
- type AfterAPIKeyRevokeFunc
- type AfterAccountLinkFunc
- type AfterPasswordChangeFunc
- type AfterRoleChangeFunc
- type AfterSessionCreateFunc
- type AfterSignInFunc
- type AfterSignOutFunc
- type AfterUserCreateFunc
- type AfterUserUpdateFunc
- type BeforeRoleChangeFunc
- type BeforeSessionCreateFunc
- type BeforeUserCreateFunc
- type BeforeUserUpdateFunc
- type Hooks
- func (h *Hooks) OnAfterAPIKeyCreate(fn AfterAPIKeyCreateFunc)
- func (h *Hooks) OnAfterAPIKeyRevoke(fn AfterAPIKeyRevokeFunc)
- func (h *Hooks) OnAfterAccountLink(fn AfterAccountLinkFunc)
- func (h *Hooks) OnAfterPasswordChange(fn AfterPasswordChangeFunc)
- func (h *Hooks) OnAfterRoleChange(fn AfterRoleChangeFunc)
- func (h *Hooks) OnAfterSessionCreate(fn AfterSessionCreateFunc)
- func (h *Hooks) OnAfterSignIn(fn AfterSignInFunc)
- func (h *Hooks) OnAfterSignOut(fn AfterSignOutFunc)
- func (h *Hooks) OnAfterUserCreate(fn AfterUserCreateFunc)
- func (h *Hooks) OnAfterUserUpdate(fn AfterUserUpdateFunc)
- func (h *Hooks) OnBeforeRoleChange(fn BeforeRoleChangeFunc)
- func (h *Hooks) OnBeforeSessionCreate(fn BeforeSessionCreateFunc)
- func (h *Hooks) OnBeforeUserCreate(fn BeforeUserCreateFunc)
- func (h *Hooks) OnBeforeUserUpdate(fn BeforeUserUpdateFunc)
- func (h *Hooks) RunAfterAPIKeyCreate(ctx context.Context, ev *APIKeyEvent)
- func (h *Hooks) RunAfterAPIKeyRevoke(ctx context.Context, ev *APIKeyEvent)
- func (h *Hooks) RunAfterAccountLink(ctx context.Context, ev *AccountLink)
- func (h *Hooks) RunAfterPasswordChange(ctx context.Context, ev *PasswordChange)
- func (h *Hooks) RunAfterRoleChange(ctx context.Context, ev *RoleChange)
- func (h *Hooks) RunAfterSessionCreate(ctx context.Context, ev *SessionCreate)
- func (h *Hooks) RunAfterSignIn(ctx context.Context, ev *SignIn)
- func (h *Hooks) RunAfterSignOut(ctx context.Context, ev *SignOut)
- func (h *Hooks) RunAfterUserCreate(ctx context.Context, ev *UserCreate)
- func (h *Hooks) RunAfterUserUpdate(ctx context.Context, ev *UserUpdate)
- func (h *Hooks) RunBeforeRoleChange(ctx context.Context, ev *RoleChange) error
- func (h *Hooks) RunBeforeSessionCreate(ctx context.Context, ev *SessionCreate) error
- func (h *Hooks) RunBeforeUserCreate(ctx context.Context, ev *UserCreate) error
- func (h *Hooks) RunBeforeUserUpdate(ctx context.Context, ev *UserUpdate) error
- type PasswordChange
- type RoleChange
- type SessionCreate
- type SignIn
- type SignOut
- type UserCreate
- type UserUpdate
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type APIKeyEvent ¶ added in v0.3.0
APIKeyEvent carries a created or a revoked API key. The plaintext key is never part of it.
type AccountLink ¶
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 ¶
AfterSignInFunc runs after commit.
type AfterSignOutFunc ¶
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 (*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 (*Hooks) OnAfterAccountLink ¶
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 (*Hooks) RunAfterAccountLink ¶
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 ¶
RunAfterSignIn runs the registered hooks after commit.
func (*Hooks) RunAfterSignOut ¶
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 ¶
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 ¶
SessionCreate carries a session creation.
type SignIn ¶
SignIn carries a completed sign-in. Method names the authentication method, for example "email", "magic-link", or a provider id.
type UserCreate ¶
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
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.