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 AfterMembershipChangeFunc
- type AfterOrganizationCreateFunc
- type AfterOrganizationDeleteFunc
- type AfterOrganizationUpdateFunc
- type AfterPasswordChangeFunc
- type AfterRoleChangeFunc
- type AfterSessionCreateFunc
- type AfterSignInFunc
- type AfterSignOutFunc
- type AfterUserCreateFunc
- type AfterUserInsertFunc
- type AfterUserUpdateFunc
- type BeforeMembershipChangeFunc
- type BeforeOrganizationCreateFunc
- type BeforeOrganizationDeleteFunc
- type BeforeOrganizationUpdateFunc
- 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) OnAfterMembershipChange(fn AfterMembershipChangeFunc)
- func (h *Hooks) OnAfterOrganizationCreate(fn AfterOrganizationCreateFunc)
- func (h *Hooks) OnAfterOrganizationDelete(fn AfterOrganizationDeleteFunc)
- func (h *Hooks) OnAfterOrganizationUpdate(fn AfterOrganizationUpdateFunc)
- 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) OnAfterUserInsert(fn AfterUserInsertFunc)
- func (h *Hooks) OnAfterUserUpdate(fn AfterUserUpdateFunc)
- func (h *Hooks) OnBeforeMembershipChange(fn BeforeMembershipChangeFunc)
- func (h *Hooks) OnBeforeOrganizationCreate(fn BeforeOrganizationCreateFunc)
- func (h *Hooks) OnBeforeOrganizationDelete(fn BeforeOrganizationDeleteFunc)
- func (h *Hooks) OnBeforeOrganizationUpdate(fn BeforeOrganizationUpdateFunc)
- 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) RunAfterMembershipChange(ctx context.Context, ev *MembershipEvent)
- func (h *Hooks) RunAfterOrganizationCreate(ctx context.Context, ev *OrganizationEvent)
- func (h *Hooks) RunAfterOrganizationDelete(ctx context.Context, ev *OrganizationEvent)
- func (h *Hooks) RunAfterOrganizationUpdate(ctx context.Context, ev *OrganizationEvent)
- 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) RunAfterUserInsert(ctx context.Context, ev *UserCreate) error
- func (h *Hooks) RunAfterUserUpdate(ctx context.Context, ev *UserUpdate)
- func (h *Hooks) RunBeforeMembershipChange(ctx context.Context, ev *MembershipEvent) error
- func (h *Hooks) RunBeforeOrganizationCreate(ctx context.Context, ev *OrganizationEvent) error
- func (h *Hooks) RunBeforeOrganizationDelete(ctx context.Context, ev *OrganizationEvent) error
- func (h *Hooks) RunBeforeOrganizationUpdate(ctx context.Context, ev *OrganizationEvent) error
- 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 MembershipEvent
- type OrganizationEvent
- 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 AfterMembershipChangeFunc ¶ added in v0.4.0
type AfterMembershipChangeFunc func(ctx context.Context, ev *MembershipEvent) error
AfterMembershipChangeFunc runs after commit.
type AfterOrganizationCreateFunc ¶ added in v0.4.0
type AfterOrganizationCreateFunc func(ctx context.Context, ev *OrganizationEvent) error
AfterOrganizationCreateFunc runs after commit.
type AfterOrganizationDeleteFunc ¶ added in v0.4.0
type AfterOrganizationDeleteFunc func(ctx context.Context, ev *OrganizationEvent) error
AfterOrganizationDeleteFunc runs after commit.
type AfterOrganizationUpdateFunc ¶ added in v0.4.0
type AfterOrganizationUpdateFunc func(ctx context.Context, ev *OrganizationEvent) error
AfterOrganizationUpdateFunc 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 AfterUserInsertFunc ¶ added in v0.4.0
type AfterUserInsertFunc func(ctx context.Context, ev *UserCreate) error
AfterUserInsertFunc runs in the transaction of the creation, after the user row exists. A hook that writes a row with a foreign key to the user needs this point, and it can still reject the creation.
type AfterUserUpdateFunc ¶ added in v0.3.0
type AfterUserUpdateFunc func(ctx context.Context, ev *UserUpdate) error
AfterUserUpdateFunc runs after commit.
type BeforeMembershipChangeFunc ¶ added in v0.4.0
type BeforeMembershipChangeFunc func(ctx context.Context, ev *MembershipEvent) error
BeforeMembershipChangeFunc runs in the transaction and can reject.
type BeforeOrganizationCreateFunc ¶ added in v0.4.0
type BeforeOrganizationCreateFunc func(ctx context.Context, ev *OrganizationEvent) error
BeforeOrganizationCreateFunc runs in the transaction and can reject.
type BeforeOrganizationDeleteFunc ¶ added in v0.4.0
type BeforeOrganizationDeleteFunc func(ctx context.Context, ev *OrganizationEvent) error
BeforeOrganizationDeleteFunc runs in the transaction and can reject. The application removes its own rows of the organization here.
type BeforeOrganizationUpdateFunc ¶ added in v0.4.0
type BeforeOrganizationUpdateFunc func(ctx context.Context, ev *OrganizationEvent) error
BeforeOrganizationUpdateFunc runs in the transaction and can reject.
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) OnAfterMembershipChange ¶ added in v0.4.0
func (h *Hooks) OnAfterMembershipChange(fn AfterMembershipChangeFunc)
OnAfterMembershipChange registers a hook that runs after commit.
func (*Hooks) OnAfterOrganizationCreate ¶ added in v0.4.0
func (h *Hooks) OnAfterOrganizationCreate(fn AfterOrganizationCreateFunc)
OnAfterOrganizationCreate registers a hook that runs after commit.
func (*Hooks) OnAfterOrganizationDelete ¶ added in v0.4.0
func (h *Hooks) OnAfterOrganizationDelete(fn AfterOrganizationDeleteFunc)
OnAfterOrganizationDelete registers a hook that runs after commit.
func (*Hooks) OnAfterOrganizationUpdate ¶ added in v0.4.0
func (h *Hooks) OnAfterOrganizationUpdate(fn AfterOrganizationUpdateFunc)
OnAfterOrganizationUpdate 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) OnAfterUserInsert ¶ added in v0.4.0
func (h *Hooks) OnAfterUserInsert(fn AfterUserInsertFunc)
OnAfterUserInsert registers a hook that runs in the transaction of the creation, after the user row exists. It can reject the creation.
func (*Hooks) OnAfterUserUpdate ¶ added in v0.3.0
func (h *Hooks) OnAfterUserUpdate(fn AfterUserUpdateFunc)
OnAfterUserUpdate registers a hook that runs after commit.
func (*Hooks) OnBeforeMembershipChange ¶ added in v0.4.0
func (h *Hooks) OnBeforeMembershipChange(fn BeforeMembershipChangeFunc)
OnBeforeMembershipChange registers a hook that runs in the transaction and can reject.
func (*Hooks) OnBeforeOrganizationCreate ¶ added in v0.4.0
func (h *Hooks) OnBeforeOrganizationCreate(fn BeforeOrganizationCreateFunc)
OnBeforeOrganizationCreate registers a hook that runs in the transaction and can reject.
func (*Hooks) OnBeforeOrganizationDelete ¶ added in v0.4.0
func (h *Hooks) OnBeforeOrganizationDelete(fn BeforeOrganizationDeleteFunc)
OnBeforeOrganizationDelete registers a hook that runs in the transaction and can reject.
func (*Hooks) OnBeforeOrganizationUpdate ¶ added in v0.4.0
func (h *Hooks) OnBeforeOrganizationUpdate(fn BeforeOrganizationUpdateFunc)
OnBeforeOrganizationUpdate registers a hook that runs in the transaction and can reject.
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) RunAfterMembershipChange ¶ added in v0.4.0
func (h *Hooks) RunAfterMembershipChange(ctx context.Context, ev *MembershipEvent)
RunAfterMembershipChange runs the registered hooks after commit.
func (*Hooks) RunAfterOrganizationCreate ¶ added in v0.4.0
func (h *Hooks) RunAfterOrganizationCreate(ctx context.Context, ev *OrganizationEvent)
RunAfterOrganizationCreate runs the registered hooks after commit.
func (*Hooks) RunAfterOrganizationDelete ¶ added in v0.4.0
func (h *Hooks) RunAfterOrganizationDelete(ctx context.Context, ev *OrganizationEvent)
RunAfterOrganizationDelete runs the registered hooks after commit.
func (*Hooks) RunAfterOrganizationUpdate ¶ added in v0.4.0
func (h *Hooks) RunAfterOrganizationUpdate(ctx context.Context, ev *OrganizationEvent)
RunAfterOrganizationUpdate 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) RunAfterUserInsert ¶ added in v0.4.0
func (h *Hooks) RunAfterUserInsert(ctx context.Context, ev *UserCreate) error
RunAfterUserInsert runs the registered hooks and stops at the first error.
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) RunBeforeMembershipChange ¶ added in v0.4.0
func (h *Hooks) RunBeforeMembershipChange(ctx context.Context, ev *MembershipEvent) error
RunBeforeMembershipChange runs the registered hooks and stops at the first error.
func (*Hooks) RunBeforeOrganizationCreate ¶ added in v0.4.0
func (h *Hooks) RunBeforeOrganizationCreate(ctx context.Context, ev *OrganizationEvent) error
RunBeforeOrganizationCreate runs the registered hooks and stops at the first error.
func (*Hooks) RunBeforeOrganizationDelete ¶ added in v0.4.0
func (h *Hooks) RunBeforeOrganizationDelete(ctx context.Context, ev *OrganizationEvent) error
RunBeforeOrganizationDelete runs the registered hooks and stops at the first error.
func (*Hooks) RunBeforeOrganizationUpdate ¶ added in v0.4.0
func (h *Hooks) RunBeforeOrganizationUpdate(ctx context.Context, ev *OrganizationEvent) error
RunBeforeOrganizationUpdate runs the registered hooks and stops at the first error.
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 MembershipEvent ¶ added in v0.4.0
type MembershipEvent struct {
// Org is the organization of the membership.
Org *store.Organization
// Membership is the row after the change. It holds the removed row for a
// removal.
Membership *store.Membership
// From is the role before a role change. It is empty for another change.
From string
// Actor is the person who runs the change.
Actor *store.User
// Tx is the transactional store of the running change.
Tx store.Store
}
MembershipEvent carries one membership change.
type OrganizationEvent ¶ added in v0.4.0
type OrganizationEvent struct {
// Org is the organization of the change.
Org *store.Organization
// Actor is the person who runs the change. It is nil for a change that no
// person started.
Actor *store.User
// Tx is the transactional store of the running change.
Tx store.Store
}
OrganizationEvent carries one organization change. A Before hook receives the transactional store, so the application writes its own rows in the same transaction.
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.