[PR #4891] [CLOSED] feat: Add Login History plugin #31242

Closed
opened 2026-04-17 22:08:30 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4891
Author: @shahradelahi
Created: 9/25/2025
Status: Closed

Base: canaryHead: feat/login-history-plugin


📝 Commits (1)

  • 2cc56e2 feat: Add Login History plugin

📊 Changes

7 files changed (+620 additions, -0 deletions)

View changed files

docs/content/docs/plugins/login-history.mdx (+138 -0)
packages/better-auth/src/plugins/login-history/client.ts (+12 -0)
packages/better-auth/src/plugins/login-history/index.ts (+145 -0)
packages/better-auth/src/plugins/login-history/login-history.test.ts (+179 -0)
packages/better-auth/src/plugins/login-history/schema.ts (+29 -0)
packages/better-auth/src/plugins/login-history/types.ts (+29 -0)
packages/better-auth/src/plugins/login-history/utils.ts (+88 -0)

📄 Description

This PR introduces the new login-history plugin, designed to give users a clear and simple audit trail of their account access. It automatically records each sign-in and sign-up, capturing the user's IP address and user agent.

I've tried to keep this plugin lightweight and unopinionated. Earlier internal versions included fields like device (from user-agent parsing) and location (from a GeoIP database), but I've removed them to avoid adding heavy dependencies and making assumptions about everyone's needs.

This is the first version, please let me know how this can be improved or what you think of it. All feedback and criticism are welcome


Summary by cubic

Adds a lightweight Login History plugin that records sign-ins and sign-ups with IP and user agent, and provides a simple API to list entries.

  • New Features

    • Records a login entry on session create (sign-in/sign-up) with userId, userAgent, ipAddress, createdAt.
    • GET /login-history/list endpoint for the authenticated user; results sorted by newest first.
    • Client plugin exposes authClient.loginHistory.list().
    • Auto-detects IP from common proxy headers; override with ipHeader option.
    • Supports custom table/field names via schema option.
    • Returns clear errors when IP or user agent is missing.
    • Added docs and tests.
  • Migration

    • Run the Better Auth CLI migrate or generate to add the loginHistory table.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/better-auth/better-auth/pull/4891 **Author:** [@shahradelahi](https://github.com/shahradelahi) **Created:** 9/25/2025 **Status:** ❌ Closed **Base:** `canary` ← **Head:** `feat/login-history-plugin` --- ### 📝 Commits (1) - [`2cc56e2`](https://github.com/better-auth/better-auth/commit/2cc56e218e3db6040f39be8d6b5b8be8861b4ea0) feat: Add Login History plugin ### 📊 Changes **7 files changed** (+620 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `docs/content/docs/plugins/login-history.mdx` (+138 -0) ➕ `packages/better-auth/src/plugins/login-history/client.ts` (+12 -0) ➕ `packages/better-auth/src/plugins/login-history/index.ts` (+145 -0) ➕ `packages/better-auth/src/plugins/login-history/login-history.test.ts` (+179 -0) ➕ `packages/better-auth/src/plugins/login-history/schema.ts` (+29 -0) ➕ `packages/better-auth/src/plugins/login-history/types.ts` (+29 -0) ➕ `packages/better-auth/src/plugins/login-history/utils.ts` (+88 -0) </details> ### 📄 Description This PR introduces the new `login-history` plugin, designed to give users a clear and simple audit trail of their account access. It automatically records each sign-in and sign-up, capturing the user's IP address and user agent. I've tried to keep this plugin lightweight and unopinionated. Earlier internal versions included fields like `device` (from user-agent parsing) and `location` (from a GeoIP database), but I've removed them to avoid adding heavy dependencies and making assumptions about everyone's needs. This is the first version, please let me know how this can be improved or what you think of it. All feedback and criticism are welcome <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds a lightweight Login History plugin that records sign-ins and sign-ups with IP and user agent, and provides a simple API to list entries. - **New Features** - Records a login entry on session create (sign-in/sign-up) with userId, userAgent, ipAddress, createdAt. - GET /login-history/list endpoint for the authenticated user; results sorted by newest first. - Client plugin exposes authClient.loginHistory.list(). - Auto-detects IP from common proxy headers; override with ipHeader option. - Supports custom table/field names via schema option. - Returns clear errors when IP or user agent is missing. - Added docs and tests. - **Migration** - Run the Better Auth CLI migrate or generate to add the loginHistory table. <!-- End of auto-generated description by cubic. --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-17 22:08:30 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#31242