[PR #5806] [MERGED] feat: add support for custom response status codes #31839

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/5806
Author: @jonathansamines
Created: 11/6/2025
Status: Merged
Merged: 11/13/2025
Merged by: @Bekacru

Base: canaryHead: feat/support-custom-response-code


📝 Commits (2)

  • 09350fe feat(better-auth): add support for custom response status codes
  • f5a925d update test

📊 Changes

3 files changed (+52 additions, -5 deletions)

View changed files

📝 packages/better-auth/src/api/routes/session.ts (+1 -0)
📝 packages/better-auth/src/api/to-auth-endpoints.test.ts (+34 -0)
📝 packages/better-auth/src/api/to-auth-endpoints.ts (+17 -5)

📄 Description

What is changing?
Updates better-auth to expose the same functionality as in https://github.com/Bekacru/better-call/pull/69 (custom response status codes via ctx.setStatus()).


Summary by cubic

Adds custom response status code support in better-auth via ctx.setStatus. Endpoints can now return a Response with the chosen status or include the status alongside the payload.

  • New Features

    • Added returnStatus option to toAuthEndpoints to include status with response and headers.
    • asResponse now respects custom status when building a Response.
    • Propagates status from thrown Response-like errors via statusCode and headers.
    • Tests cover both asResponse and returnStatus flows with a 201 status.
  • Migration

    • No changes required. Use c.setStatus(...) and opt in with { asResponse: true } or { returnStatus: true }.
    • Defaults remain unchanged; session route sets returnStatus to false.

Written for commit f5a925d824. Summary will update automatically 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/5806 **Author:** [@jonathansamines](https://github.com/jonathansamines) **Created:** 11/6/2025 **Status:** ✅ Merged **Merged:** 11/13/2025 **Merged by:** [@Bekacru](https://github.com/Bekacru) **Base:** `canary` ← **Head:** `feat/support-custom-response-code` --- ### 📝 Commits (2) - [`09350fe`](https://github.com/better-auth/better-auth/commit/09350fee3d260240a9d8d3b812d81da991785347) feat(better-auth): add support for custom response status codes - [`f5a925d`](https://github.com/better-auth/better-auth/commit/f5a925d8246646568497b562c0ca1e8fc592ce03) update test ### 📊 Changes **3 files changed** (+52 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `packages/better-auth/src/api/routes/session.ts` (+1 -0) 📝 `packages/better-auth/src/api/to-auth-endpoints.test.ts` (+34 -0) 📝 `packages/better-auth/src/api/to-auth-endpoints.ts` (+17 -5) </details> ### 📄 Description **What is changing?** Updates `better-auth` to expose the same functionality as in https://github.com/Bekacru/better-call/pull/69 (custom response status codes via `ctx.setStatus()`). <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds custom response status code support in better-auth via ctx.setStatus. Endpoints can now return a Response with the chosen status or include the status alongside the payload. - **New Features** - Added returnStatus option to toAuthEndpoints to include status with response and headers. - asResponse now respects custom status when building a Response. - Propagates status from thrown Response-like errors via statusCode and headers. - Tests cover both asResponse and returnStatus flows with a 201 status. - **Migration** - No changes required. Use c.setStatus(...) and opt in with { asResponse: true } or { returnStatus: true }. - Defaults remain unchanged; session route sets returnStatus to false. <sup>Written for commit f5a925d8246646568497b562c0ca1e8fc592ce03. Summary will update automatically 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 22:42:57 -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#31839