hooks

command
v2.13.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

hooks

Wires every Config.LifecycleHooks callback to a log line so you can see when each one fires. Password sign-in with a TOTP second factor, in memory.

Run

go run ./examples/hooks

Then drive the API (a cookie jar keeps the session):

curl -c jar -s -XPOST localhost:8080/auth/signup -d '{"email":"a@example.com","password":"twelve-chars-min"}'   # OnSignup
curl -c jar -s -XPOST localhost:8080/auth/signin -d '{"email":"a@example.com","password":"twelve-chars-min"}'   # OnSignin

TOTP enrollment (/auth/totp/enroll/*) fires OnMFAEnabled, and a sign-in held for a second factor fires OnSignin when /auth/totp/verify succeeds.

Notes

  • Hooks run after the action committed, so they are observe-only. A returned error or a panic is logged, passed to OnHookError, and does not fail the request.
  • To refuse a signup or sign-in before it happens, gate it ahead of the library (wrap the route, or check the address first).
  • OnTokenIssued is the one hook that can fail a request, because the token is not yet minted. It is set on the same LifecycleHooks struct and only matters when the authorization server is enabled.

ENCRYPTION_KEY (32 bytes) protects TOTP secrets at rest; the default is for local use only. See docs/hooks.md.

Documentation

Overview

Command hooks demos Config.LifecycleHooks: /auth/* routes with TOTP enabled and every observe-only hook logging a structured line. Hooks run after the action commits, so they cannot veto it. Signup fires OnSignup, signin and TOTP verify fire OnSignin, and enrollment fires OnMFAEnabled.

Jump to

Keyboard shortcuts

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