Events
The auth service reports what happens to accounts and sessions as events: logins, failures, sessions created and revoked, reused refresh tokens. Use them for an audit log, security alerts, or an outbox.
dataProvider.recordEvent(event)stores the event inside the transaction of its step, withdataProvider.transaction(): the login and its audit row are written together, or not at all. An error fails the step.onEvent(event)is called after the step is committed: logs, metrics. Its errors are logged and ignored.
onLoginSuccess, onLoginFailed and onRefreshTokenReuse are also available, as shortcuts.
Transactions
With transaction(fn), the steps that write several records (login, refresh token rotation, logout, revocations) run in one database transaction, and every call of the step goes to the data provider fn receives:
Without it, each method of the data provider must be atomic on its own.
Fields
Every event has a type, an occurredAt date, and when they apply, userId, sessionId (the sid claim of the tokens) and meta: the request (ipAddress, userAgent, requestId, clientId). Service calls outside a request, like revokeUserSessions(), have no meta. Events never carry a password, a token or a code.
identifierHash is the SHA-256 of the normalized username: it correlates the attempts on an account without storing what was typed.
AuthEvent is a discriminated union on type: