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

Closed
opened 2026-04-13 10:29:41 -05:00 by GiteaMirror · 0 comments
Owner

Original Pull Request: https://github.com/better-auth/better-auth/pull/8589

State: closed
Merged: Yes


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.

**Original Pull Request:** https://github.com/better-auth/better-auth/pull/8589 **State:** closed **Merged:** Yes --- ## 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. -->
GiteaMirror added the pull-request label 2026-04-13 10:29:41 -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#16329