[PR #8589] [MERGED] fix(last-login-method): normalize missing resolver path #24983

Closed
opened 2026-04-15 22:40:16 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8589
Author: @mrgrauel
Created: 3/13/2026
Status: Merged
Merged: 3/20/2026
Merged by: @himself65

Base: canaryHead: fix/harden-last-method-plugin


📝 Commits (9)

  • bfd80f6 fix(last-login-method): normalize missing resolver path
  • 53c4560 Merge branch 'canary' into fix/harden-last-method-plugin
  • 4315e45 Merge branch 'canary' into fix/harden-last-method-plugin
  • 9a36194 Merge branch 'canary' into fix/harden-last-method-plugin
  • 9e7300b Merge branch 'canary' into fix/harden-last-method-plugin
  • b11e36d Merge branch 'canary' into fix/harden-last-method-plugin
  • 4ca63f2 Merge branch 'canary' into fix/harden-last-method-plugin
  • eace76b Merge branch 'canary' into fix/harden-last-method-plugin
  • dfe0f95 Merge branch 'canary' into fix/harden-last-method-plugin

📊 Changes

2 files changed (+158 additions, -20 deletions)

View changed files

📝 packages/better-auth/src/plugins/last-login-method/index.ts (+24 -19)
📝 packages/better-auth/src/plugins/last-login-method/last-login-method.test.ts (+134 -1)

📄 Description

Summary

  • normalize missing ctx.path before invoking built-in and custom last-login-method resolvers
  • route database-hook and after-hook resolution through a shared helper
  • add regression coverage for missing-path contexts and custom resolvers in database hooks

Testing

  • pnpm --filter better-auth exec vitest run src/plugins/last-login-method/last-login-method.test.ts
  • pnpm --filter better-auth exec biome check src/plugins/last-login-method/index.ts src/plugins/last-login-method/last-login-method.test.ts

Summary by cubic

Fixes the better-auth last-login-method plugin to safely handle missing ctx.path by normalizing it and routing all resolution through a shared helper. Prevents incorrect method detection and avoids cookie/DB writes when the path is absent across middleware and database/after hooks.

  • Bug Fixes
    • Normalize missing ctx.path to "" for both default and custom resolvers; default returns null on empty paths.
    • Centralize resolution in resolveMethod used by middleware and database hooks; add regression tests to ensure custom resolvers get path: "" and no writes occur on missing paths.

Written for commit dfe0f95623. Summary will update on new commits.


🔄 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/8589 **Author:** [@mrgrauel](https://github.com/mrgrauel) **Created:** 3/13/2026 **Status:** ✅ Merged **Merged:** 3/20/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `fix/harden-last-method-plugin` --- ### 📝 Commits (9) - [`bfd80f6`](https://github.com/better-auth/better-auth/commit/bfd80f675238c68df21305e134b9bc0e60f08d12) fix(last-login-method): normalize missing resolver path - [`53c4560`](https://github.com/better-auth/better-auth/commit/53c4560074f8867f5ce157fcd5640d7d86b58e27) Merge branch 'canary' into fix/harden-last-method-plugin - [`4315e45`](https://github.com/better-auth/better-auth/commit/4315e454fb2aca6fb99b44310d9027c3c903a78c) Merge branch 'canary' into fix/harden-last-method-plugin - [`9a36194`](https://github.com/better-auth/better-auth/commit/9a36194b0f6e803f775fb9955fcea9fb5795a93d) Merge branch 'canary' into fix/harden-last-method-plugin - [`9e7300b`](https://github.com/better-auth/better-auth/commit/9e7300bd88c10d54ee5c905a3db11b3a9dc7d05f) Merge branch 'canary' into fix/harden-last-method-plugin - [`b11e36d`](https://github.com/better-auth/better-auth/commit/b11e36de74bee481d381aaf2e1b7031805791ebd) Merge branch 'canary' into fix/harden-last-method-plugin - [`4ca63f2`](https://github.com/better-auth/better-auth/commit/4ca63f2adf1276561ff6466233691cb18a92b422) Merge branch 'canary' into fix/harden-last-method-plugin - [`eace76b`](https://github.com/better-auth/better-auth/commit/eace76b35550f52b5ec31f39f96892217df9491a) Merge branch 'canary' into fix/harden-last-method-plugin - [`dfe0f95`](https://github.com/better-auth/better-auth/commit/dfe0f95623bd1a1d9bbc9549ec22e02d42228458) Merge branch 'canary' into fix/harden-last-method-plugin ### 📊 Changes **2 files changed** (+158 additions, -20 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/last-login-method/index.ts` (+24 -19) 📝 `packages/better-auth/src/plugins/last-login-method/last-login-method.test.ts` (+134 -1) </details> ### 📄 Description ## Summary - normalize missing `ctx.path` before invoking built-in and custom last-login-method resolvers - route database-hook and after-hook resolution through a shared helper - add regression coverage for missing-path contexts and custom resolvers in database hooks ## Testing - `pnpm --filter better-auth exec vitest run src/plugins/last-login-method/last-login-method.test.ts` - `pnpm --filter better-auth exec biome check src/plugins/last-login-method/index.ts src/plugins/last-login-method/last-login-method.test.ts` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Fixes the `better-auth` last-login-method plugin to safely handle missing `ctx.path` by normalizing it and routing all resolution through a shared helper. Prevents incorrect method detection and avoids cookie/DB writes when the path is absent across middleware and database/after hooks. - **Bug Fixes** - Normalize missing `ctx.path` to "" for both default and custom resolvers; default returns null on empty paths. - Centralize resolution in `resolveMethod` used by middleware and database hooks; add regression tests to ensure custom resolvers get `path: ""` and no writes occur on missing paths. <sup>Written for commit dfe0f95623bd1a1d9bbc9549ec22e02d42228458. Summary will update on new commits.</sup> <!-- 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-15 22:40:16 -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#24983