Skip to main content
The last login module records every successful authentication event per user. You can show users when and how they last signed in on a security page, or use login history to detect unusual activity.

Setup

createLastLoginModule is stateless and safe to call multiple times against the same database instance.

Recording a login

Call recordLogin after any successful authentication:
Older entries beyond maxHistoryPerUser (default: 10) are pruned automatically on every write.

Reading login data

Last login

Returns null in data when no history exists for the user.

Full history

Events are returned newest first. The optional limit parameter overrides the module’s maxHistoryPerUser.

Supported methods

Result type

All methods return Result<T>, either { success: true; data: T } or { success: false; error: KavachError }. No exceptions are thrown.
IP addresses are stored as-is. Normalise or hash them before passing if your privacy policy requires it.
Last modified on April 29, 2026