[PR #4693] [MERGED] feat(last-login-method): update OAuth login method tracking for multiple auth type #5534

Closed
opened 2026-03-13 12:26:18 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/4693
Author: @Kinfe123
Created: 9/16/2025
Status: Merged
Merged: 9/18/2025
Merged by: @himself65

Base: canaryHead: fix/last-login-method-oauth-update


📝 Commits (3)

  • 120c0ff fix(last-login-method): update lastLoginMethod on OAuth logins via session.create.after hook
  • f58366d lint
  • 3fa015b Merge branch 'canary' into fix/last-login-method-oauth-update

📊 Changes

2 files changed (+193 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/plugins/last-login-method/index.ts (+22 -0)
📝 packages/better-auth/src/plugins/last-login-method/last-login-method.test.ts (+171 -2)

📄 Description

  • Fix GitHub issue #4627 where lastLoginMethod was only set during user creation
  • Add session.create.after hook to update lastLoginMethod on all login types
  • Use direct adapter.update() to bypass validation issues with updateUser()
  • Add comprehensive test coverage for OAuth account linking scenarios
  • Ensure cross-device consistency for lastLoginMethod tracking

Fixes #4627


Summary by cubic

Updates lastLoginMethod on every sign-in using a new session.create.after hook. Fixes #4627 by correctly tracking email and OAuth logins, including account linking and cross-device sessions.

  • Bug Fixes
    • Update lastLoginMethod after session creation for all auth types.
    • Persist via internalAdapter.updateUser to avoid updateUser validation issues.
    • Set last_used_login_method during OAuth callbacks for cross-device consistency.
    • Add tests for repeated logins and email→OAuth account linking.

🔄 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/4693 **Author:** [@Kinfe123](https://github.com/Kinfe123) **Created:** 9/16/2025 **Status:** ✅ Merged **Merged:** 9/18/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/last-login-method-oauth-update` --- ### 📝 Commits (3) - [`120c0ff`](https://github.com/better-auth/better-auth/commit/120c0ffb9d8075d76834ee97550f7f6f129bef7e) fix(last-login-method): update lastLoginMethod on OAuth logins via session.create.after hook - [`f58366d`](https://github.com/better-auth/better-auth/commit/f58366da596f0dc8c238e0bf242591f2720dd922) lint - [`3fa015b`](https://github.com/better-auth/better-auth/commit/3fa015b67cb681709c2be5363e06237c763ec8cf) Merge branch 'canary' into fix/last-login-method-oauth-update ### 📊 Changes **2 files changed** (+193 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/last-login-method/index.ts` (+22 -0) 📝 `packages/better-auth/src/plugins/last-login-method/last-login-method.test.ts` (+171 -2) </details> ### 📄 Description - Fix GitHub issue #4627 where lastLoginMethod was only set during user creation - Add session.create.after hook to update lastLoginMethod on all login types - Use direct adapter.update() to bypass validation issues with updateUser() - Add comprehensive test coverage for OAuth account linking scenarios - Ensure cross-device consistency for lastLoginMethod tracking Fixes #4627 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Updates lastLoginMethod on every sign-in using a new session.create.after hook. Fixes #4627 by correctly tracking email and OAuth logins, including account linking and cross-device sessions. - **Bug Fixes** - Update lastLoginMethod after session creation for all auth types. - Persist via internalAdapter.updateUser to avoid updateUser validation issues. - Set last_used_login_method during OAuth callbacks for cross-device consistency. - Add tests for repeated logins and email→OAuth account linking. <!-- 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-03-13 12:26:18 -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#5534