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 build your own checks on the login history. theAuth’s sign-in modules do not call this module for you, so you call recordLogin yourself after each successful sign-in.

Setup

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

Recording a login

Call recordLogin after any successful authentication. It validates its input (the userId must be non-empty and the method must be one of the values below) and returns a Result with the stored event:
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: TheAuthError }. Invalid input and database failures come back as success: false rather than thrown errors.
IP addresses are stored as-is. Normalise or hash them before passing if your privacy policy requires it.

Authentication overview

All supported auth methods that generate login events.

Anomaly detection

What exists today for unusual behavior (theAuth has no login anomaly detector).

Trusted devices

Skip 2FA on devices you have marked as trusted.

Audit trail

Full agent-level action log for deeper activity analysis.
Last modified on October 7, 2026