[PR #7734] docs: improve Next.js auth protection clarity and structure #15768

Open
opened 2026-04-13 10:12:55 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/better-auth/better-auth/pull/7734
Author: @Emmaccen
Created: 1/31/2026
Status: 🔄 Open

Base: mainHead: docs/improve-nextjs-auth-protection


📝 Commits (1)

  • 303a13c docs: improve Next.js auth protection clarity and structure

📊 Changes

1 file changed (+107 additions, -148 deletions)

View changed files

📝 docs/content/docs/integrations/next.mdx (+107 -148)

📄 Description

Problem:

The Auth Protection section leads with advanced edge cases, making it confusing for developers on standard Next.js versions. The performance implications of middleware database calls aren't clearly stated upfront.

Solution:

Restructured to lead with the recommended approach (cookie-based middleware check), added clear performance warnings, and moved advanced options to the bottom. Added explanations of WHY to use each approach.

Testing:

Tested docs locally with pnpm -F docs dev, verified all code examples and callouts render correctly. No linter warning, and formatted with pnpm format


Summary by cubic

Rewrote the Next.js Auth Protection docs to lead with a fast cookie-based middleware check and require full session validation in pages/routes. Added clear performance and security warnings and updated examples for Next.js 16 proxy and earlier versions.

  • Refactors
    • Put recommended flow first; moved advanced middleware validation to the end.
    • Added examples: middleware cookie check, page-level auth.api.getSession with redirect, and getCookieCache.
    • Updated version guidance: Next 16 proxy + migration notes; Node.js runtime for 15.2+; Edge runtime HTTP fetch for 13–15.1.x.
    • Clarified cookie config for getSessionCookie and highlighted that cookie checks alone are not secure.

Written for commit 303a13ceaf. 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/7734 **Author:** [@Emmaccen](https://github.com/Emmaccen) **Created:** 1/31/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `docs/improve-nextjs-auth-protection` --- ### 📝 Commits (1) - [`303a13c`](https://github.com/better-auth/better-auth/commit/303a13ceaf33ae5cd85efffc748b0a82ae43ebcd) docs: improve Next.js auth protection clarity and structure ### 📊 Changes **1 file changed** (+107 additions, -148 deletions) <details> <summary>View changed files</summary> 📝 `docs/content/docs/integrations/next.mdx` (+107 -148) </details> ### 📄 Description ## Problem: The Auth Protection section leads with advanced edge cases, making it confusing for developers on standard Next.js versions. The performance implications of middleware database calls aren't clearly stated upfront. ## Solution: Restructured to lead with the recommended approach (cookie-based middleware check), added clear performance warnings, and moved advanced options to the bottom. Added explanations of WHY to use each approach. ### Testing: Tested docs locally with `pnpm -F docs dev`, verified all code examples and callouts render correctly. No linter warning, and formatted with `pnpm format` <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Rewrote the Next.js Auth Protection docs to lead with a fast cookie-based middleware check and require full session validation in pages/routes. Added clear performance and security warnings and updated examples for Next.js 16 proxy and earlier versions. - **Refactors** - Put recommended flow first; moved advanced middleware validation to the end. - Added examples: middleware cookie check, page-level auth.api.getSession with redirect, and getCookieCache. - Updated version guidance: Next 16 proxy + migration notes; Node.js runtime for 15.2+; Edge runtime HTTP fetch for 13–15.1.x. - Clarified cookie config for getSessionCookie and highlighted that cookie checks alone are not secure. <sup>Written for commit 303a13ceaf33ae5cd85efffc748b0a82ae43ebcd. 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-13 10:12:55 -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#15768