[PR #8026] [MERGED] fix(admin): optional chain user in hooks #33295

Closed
opened 2026-04-17 23:56:01 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/8026
Author: @jslno
Created: 2/17/2026
Status: Merged
Merged: 2/18/2026
Merged by: @himself65

Base: canaryHead: 02-17-2025/admin-optional-chaining


📝 Commits (2)

  • 6ad834b fix(admin): optional chain user in hooks
  • fb011ba chore: update type

📊 Changes

1 file changed (+2 additions, -2 deletions)

View changed files

📝 packages/better-auth/src/plugins/admin/admin.ts (+2 -2)

📄 Description

closes #8022


Summary by cubic

Prevented admin hook crashes when no user is found by allowing a null user and guarding ban checks with optional chaining. Aligns with #8022 to handle missing users safely.

  • Bug Fixes
    • Cast findUserById to UserWithRole | null.
    • Use user?.banned to avoid accessing properties on null.

Written for commit fb011ba811. 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/8026 **Author:** [@jslno](https://github.com/jslno) **Created:** 2/17/2026 **Status:** ✅ Merged **Merged:** 2/18/2026 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `02-17-2025/admin-optional-chaining` --- ### 📝 Commits (2) - [`6ad834b`](https://github.com/better-auth/better-auth/commit/6ad834b6a4e6500ec0948f1c7948bad136b0100a) fix(admin): optional chain user in hooks - [`fb011ba`](https://github.com/better-auth/better-auth/commit/fb011ba8115913cb95f9128e4bf6381bf2bed3d8) chore: update type ### 📊 Changes **1 file changed** (+2 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/plugins/admin/admin.ts` (+2 -2) </details> ### 📄 Description closes #8022 <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Prevented admin hook crashes when no user is found by allowing a null user and guarding ban checks with optional chaining. Aligns with #8022 to handle missing users safely. - **Bug Fixes** - Cast findUserById to UserWithRole | null. - Use user?.banned to avoid accessing properties on null. <sup>Written for commit fb011ba8115913cb95f9128e4bf6381bf2bed3d8. 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-17 23:56:01 -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#33295