[PR #6495] [MERGED] docs: add middleware section for TanStack Start #32304

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

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/6495
Author: @TheOrcDev
Created: 12/3/2025
Status: Merged
Merged: 12/3/2025
Merged by: @himself65

Base: canaryHead: docs/tanstack-start-middleware


📝 Commits (1)

  • d4a6e3b docs: add middleware example for route protection in TanStack integration

📊 Changes

1 file changed (+41 additions, -0 deletions)

View changed files

📝 docs/content/docs/integrations/tanstack.mdx (+41 -0)

📄 Description

Middleware Integration with Better Auth

This PR adds documentation for using TanStack Start's middleware feature together with Better Auth to protect routes that require authentication.


🔧 Changes

Added

  • A new Middleware section in the TanStack Start integration docs.
  • A complete example demonstrating how to create an authentication middleware that:
    • Checks for a valid session using auth.api.getSession()
    • Redirects unauthenticated users to the login page
    • Applies the middleware to route definitions via the server.middleware array

🧠 Why This Is Needed

The existing TanStack Start integration docs only covered:

  • Mounting the auth handler
  • Managing cookies

However, they didn’t explain how to protect routes from unauthenticated users a very common requirement.

This PR fills that gap by documenting how to leverage TanStack Start’s built-in middleware system to guard pages using Better Auth, making it easier for developers to build secure applications.



Summary by cubic

Adds middleware docs to the TanStack Start + Better Auth integration to show how to protect routes by checking the session and redirecting to /login when not authenticated. This fills the gap in the guide so developers can guard pages easily.

  • New Features
    • New Middleware section with an auth middleware example using auth.api.getSession and redirect.
    • Route usage example showing server.middleware to protect specific pages.

Written for commit d4a6e3be69. 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/6495 **Author:** [@TheOrcDev](https://github.com/TheOrcDev) **Created:** 12/3/2025 **Status:** ✅ Merged **Merged:** 12/3/2025 **Merged by:** [@himself65](https://github.com/himself65) **Base:** `canary` ← **Head:** `docs/tanstack-start-middleware` --- ### 📝 Commits (1) - [`d4a6e3b`](https://github.com/better-auth/better-auth/commit/d4a6e3be693df775572e6d2d97f04776b92f53f5) docs: add middleware example for route protection in TanStack integration ### 📊 Changes **1 file changed** (+41 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/integrations/tanstack.mdx` (+41 -0) </details> ### 📄 Description ## Middleware Integration with Better Auth This PR adds documentation for using **TanStack Start's middleware** feature together with **Better Auth** to protect routes that require authentication. --- ## 🔧 Changes ### ➕ Added - A new **Middleware** section in the TanStack Start integration docs. - A complete example demonstrating how to create an authentication middleware that: - Checks for a valid session using `auth.api.getSession()` - Redirects unauthenticated users to the login page - Applies the middleware to route definitions via the `server.middleware` array --- ## 🧠 Why This Is Needed The existing TanStack Start integration docs only covered: - Mounting the auth handler - Managing cookies However, they didn’t explain how to **protect routes from unauthenticated users** a very common requirement. This PR fills that gap by documenting how to leverage TanStack Start’s built-in middleware system to guard pages using Better Auth, making it easier for developers to build secure applications. --- <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Adds middleware docs to the TanStack Start + Better Auth integration to show how to protect routes by checking the session and redirecting to /login when not authenticated. This fills the gap in the guide so developers can guard pages easily. - **New Features** - New Middleware section with an auth middleware example using auth.api.getSession and redirect. - Route usage example showing server.middleware to protect specific pages. <sup>Written for commit d4a6e3be693df775572e6d2d97f04776b92f53f5. 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 23:08:56 -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#32304