[GH-ISSUE #6853] [Issue] NextJS 16, Server Error #19285

Closed
opened 2026-04-15 18:10:20 -05:00 by GiteaMirror · 7 comments
Owner

Originally created by @niassuh1 on GitHub (Dec 18, 2025).
Original GitHub issue: https://github.com/better-auth/better-auth/issues/6853

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

1.Run pnpm run dev
2. Login using Keycloak after proper setup
3. Login successful
4. Shut down the app
5. Run the app again
6. Gets an error

Screenshot

Image

Logs

Image

Current vs. Expected behavior

It should open the "/" page correctly

What version of Better Auth are you using?

1.4.7

System info

{
  "system": {
    "platform": "win32",
    "arch": "x64",
    "version": "Windows 11 Home",
    "release": "10.0.26100",
    "cpuCount": 16,
    "cpuModel": "AMD Ryzen 7 6800H with Radeon Graphics         ",
    "totalMemory": "31.25 GB",
    "freeMemory": "6.62 GB"
  },
  "node": {
    "version": "v22.20.0",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.2"
  },
  "frameworks": [
    {
      "name": "next",
      "version": "16.0.10"
    },
    {
      "name": "react",
      "version": "19.2.1"
    }
  ],
  "databases": null,
  "betterAuth": {
    "version": "^1.4.7",
    "config": {
      "plugins": [
        {
          "name": "generic-oauth",
          "config": {
            "id": "generic-oauth",
            "endpoints": {},
            "$ERROR_CODES": {
              "INVALID_OAUTH_CONFIGURATION": "Invalid OAuth configuration",
              "TOKEN_URL_NOT_FOUND": "Invalid OAuth configuration. Token URL not found.",
              "PROVIDER_CONFIG_NOT_FOUND": "No config found for provider",
              "PROVIDER_ID_REQUIRED": "Provider ID is required",
              "INVALID_OAUTH_CONFIG": "Invalid OAuth configuration.",
              "SESSION_REQUIRED": "Session is required"
            }
          }
        },
        {
          "name": "next-cookies",
          "config": {
            "id": "next-cookies",
            "hooks": {
              "after": [
                {}
              ]
            }
          }
        }
      ]
    }
  }
}

Which area(s) are affected? (Select all that apply)

Backend, Client

Auth config (if applicable)

import { betterAuth } from "better-auth";
import { nextCookies } from "better-auth/next-js";
import { genericOAuth, keycloak, multiSession } from "better-auth/plugins";

export const auth = betterAuth({
  plugins: [
    genericOAuth({
      config: [
        keycloak({
          clientId: "CLIENT_ID",
          clientSecret: "CLIENT_SECRET",
          issuer: "http://localhost:8081/realms/MY_REALM",
          scopes: ["profile email"],
        }),
      ],
    }),
    nextCookies(),
  ],
});

Additional context

This is how my proxy.ts look like

import { NextRequest, NextResponse } from "next/server";
import { getSessionCookie } from "better-auth/cookies";
import { auth } from "./lib/auth";
export async function proxy(request: NextRequest) {
  const sessionCookie = getSessionCookie(request);

  if (!sessionCookie) {
    const { url } = await auth.api.signInWithOAuth2({
      headers: request.headers,
      body: {
        providerId: "keycloak",
      },
    });
    return NextResponse.redirect(url);
  }
  return NextResponse.next();
}
export const config = {
  matcher: ["/"], // Specify the routes the middleware applies to
};

Originally created by @niassuh1 on GitHub (Dec 18, 2025). Original GitHub issue: https://github.com/better-auth/better-auth/issues/6853 ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce 1.Run `pnpm run dev` 2. Login using **Keycloak** after proper setup 3. Login successful 4. Shut down the app 5. Run the app again 6. Gets an error ## Screenshot <img width="596" height="746" alt="Image" src="https://github.com/user-attachments/assets/aee1d7a7-4a0a-42e7-ac15-92f7cd5df1ab" /> ## Logs <img width="880" height="242" alt="Image" src="https://github.com/user-attachments/assets/506fd5ec-3ca0-4401-953e-b7c6e0e74c44" /> ### Current vs. Expected behavior It should open the "/" page correctly ### What version of Better Auth are you using? 1.4.7 ### System info ```bash { "system": { "platform": "win32", "arch": "x64", "version": "Windows 11 Home", "release": "10.0.26100", "cpuCount": 16, "cpuModel": "AMD Ryzen 7 6800H with Radeon Graphics ", "totalMemory": "31.25 GB", "freeMemory": "6.62 GB" }, "node": { "version": "v22.20.0", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.2" }, "frameworks": [ { "name": "next", "version": "16.0.10" }, { "name": "react", "version": "19.2.1" } ], "databases": null, "betterAuth": { "version": "^1.4.7", "config": { "plugins": [ { "name": "generic-oauth", "config": { "id": "generic-oauth", "endpoints": {}, "$ERROR_CODES": { "INVALID_OAUTH_CONFIGURATION": "Invalid OAuth configuration", "TOKEN_URL_NOT_FOUND": "Invalid OAuth configuration. Token URL not found.", "PROVIDER_CONFIG_NOT_FOUND": "No config found for provider", "PROVIDER_ID_REQUIRED": "Provider ID is required", "INVALID_OAUTH_CONFIG": "Invalid OAuth configuration.", "SESSION_REQUIRED": "Session is required" } } }, { "name": "next-cookies", "config": { "id": "next-cookies", "hooks": { "after": [ {} ] } } } ] } } } ``` ### Which area(s) are affected? (Select all that apply) Backend, Client ### Auth config (if applicable) ```typescript import { betterAuth } from "better-auth"; import { nextCookies } from "better-auth/next-js"; import { genericOAuth, keycloak, multiSession } from "better-auth/plugins"; export const auth = betterAuth({ plugins: [ genericOAuth({ config: [ keycloak({ clientId: "CLIENT_ID", clientSecret: "CLIENT_SECRET", issuer: "http://localhost:8081/realms/MY_REALM", scopes: ["profile email"], }), ], }), nextCookies(), ], }); ``` ### Additional context This is how my `proxy.ts` look like ```ts import { NextRequest, NextResponse } from "next/server"; import { getSessionCookie } from "better-auth/cookies"; import { auth } from "./lib/auth"; export async function proxy(request: NextRequest) { const sessionCookie = getSessionCookie(request); if (!sessionCookie) { const { url } = await auth.api.signInWithOAuth2({ headers: request.headers, body: { providerId: "keycloak", }, }); return NextResponse.redirect(url); } return NextResponse.next(); } export const config = { matcher: ["/"], // Specify the routes the middleware applies to }; ```
GiteaMirror added the platformoauthbug labels 2026-04-15 18:10:20 -05:00
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 18, 2025):

Tag @better-auth-agent if you would like an answer from the Agent

If you need more help, tag @better-auth-agent in a comment so I can respond.

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3669944588 --> @better-auth-agent[bot] commented on GitHub (Dec 18, 2025): Tag @better-auth-agent if you would like an answer from the Agent _If you need more help, tag @better-auth-agent in a comment so I can respond._ <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@dosubot[bot] commented on GitHub (Dec 18, 2025):

Hi @niassuh1! I'm Dosu and I’m helping the better-auth team.

The error after restarting your Next.js 16 app is likely because Better Auth sessions are not persisted across server restarts unless you configure persistent storage (like a database or Redis). By default, session data is stored in memory or cookies, so when you restart the app, all sessions are lost and users get a 401 Unauthorized error until they log in again. To fix this, you should either:

  • Add a database or secondary storage (e.g., Redis) to your Better Auth config for persistent sessions across restarts, or
  • Explicitly enable and configure stateless cookie caching in your Better Auth config if you want to operate without a database. This stores session data in signed/encrypted cookies, but persistence is limited to the cookie's lifetime and browser context. See Better Auth session management docs.

Also, with Next.js 16, make sure you use the "use cache: private" directive for session-related routes/components to avoid issues with header caching, and consider using more specific middleware matchers (like /dashboard) instead of / for reliable session checks source.

If you initiate OAuth login server-side, set asResponse: true in signInWithOAuth2 to ensure cookies are set correctly in the response source.

Finally, double-check your cookie attributes (sameSite, secure, httpOnly, domain) for consistency between OAuth requests and callbacks, especially in development environments source.

If you need persistent sessions, update your config to use a database or enable cookie caching. If you want stateless sessions, configure session.cookieCache as shown in the docs.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other

Chat with Dosu Open in Cursor Join Discord Share on X

<!-- gh-comment-id:3669959552 --> @dosubot[bot] commented on GitHub (Dec 18, 2025): <!-- Greeting --> Hi @niassuh1! I'm [Dosu](https://go.dosu.dev/dosubot) and I’m helping the better-auth team. <!-- Answer --> The error after restarting your Next.js 16 app is likely because Better Auth sessions are not persisted across server restarts unless you configure persistent storage (like a database or Redis). By default, session data is stored in memory or cookies, so when you restart the app, all sessions are lost and users get a 401 Unauthorized error until they log in again. To fix this, you should either: - Add a database or secondary storage (e.g., Redis) to your Better Auth config for persistent sessions across restarts, or - Explicitly enable and configure stateless cookie caching in your Better Auth config if you want to operate without a database. This stores session data in signed/encrypted cookies, but persistence is limited to the cookie's lifetime and browser context. See [Better Auth session management docs](https://github.com/better-auth/better-auth/blob/91cea0d0a79e6009eccda62e43c39cb44ef59625/docs/content/docs/concepts/session-management.mdx#L6-L350). Also, with Next.js 16, make sure you use the `"use cache: private"` directive for session-related routes/components to avoid issues with header caching, and consider using more specific middleware matchers (like `/dashboard`) instead of `/` for reliable session checks [source](https://github.com/better-auth/better-auth/issues/2143). If you initiate OAuth login server-side, set `asResponse: true` in `signInWithOAuth2` to ensure cookies are set correctly in the response [source](https://github.com/better-auth/better-auth/issues/6535). Finally, double-check your cookie attributes (`sameSite`, `secure`, `httpOnly`, `domain`) for consistency between OAuth requests and callbacks, especially in development environments [source](https://github.com/better-auth/better-auth/issues/5658). If you need persistent sessions, update your config to use a database or enable cookie caching. If you want stateless sessions, configure `session.cookieCache` as shown in the docs. <!-- Dosu Comment Footer --> *To reply, just mention [@dosu](https://go.dosu.dev/dosubot).* --- <sup>How did I do? [Good](https://app.dosu.dev/response-feedback/b4f892f2-6e36-40a6-a7c1-ee8d87d05552?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/b4f892f2-6e36-40a6-a7c1-ee8d87d05552?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/b4f892f2-6e36-40a6-a7c1-ee8d87d05552?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/b4f892f2-6e36-40a6-a7c1-ee8d87d05552?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/b4f892f2-6e36-40a6-a7c1-ee8d87d05552?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/b4f892f2-6e36-40a6-a7c1-ee8d87d05552?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/b4f892f2-6e36-40a6-a7c1-ee8d87d05552?feedback_type=other)</sup> [![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&nbsp;[![Open in Cursor](https://dosu.dev/dosu-in-cursor.svg)](https://cursor.com/link/prompt?text=The%20error%20after%20restarting%20your%20Next.js%2016%20app%20is%20likely%20because%20Better%20Auth%20sessions%20are%20not%20persisted%20across%20server%20restarts%20unless%20you%20configure%20persistent%20storage%20%28like%20a%20database%20or%20Redis%29.%20By%20default%2C%20session%20data%20is%20stored%20in%20memory%20or%20cookies%2C%20so%20when%20you%20restart%20the%20app%2C%20all%20sessions%20are%20lost%20and%20users%20get%20a%20401%20Unauthorized%20error%20until%20they%20log%20in%20again.%20To%20fix%20this%2C%20you%20should%20either%3A%0A%0A-%20Add%20a%20database%20or%20secondary%20storage%20%28e.g.%2C%20Redis%29%20to%20your%20Better%20Auth%20config%20for%20persistent%20sessions%20across%20restarts%2C%20or%0A-%20Explicitly%20enable%20and%20configure%20stateless%20cookie%20caching%20in%20your%20Better%20Auth%20config%20if%20you%20want%20to%20operate%20without%20a%20database.%20This%20stores%20session%20data%20in%20signed/encrypted%20cookies%2C%20but%20persistence%20is%20limited%20to%20the%20cookie%27s%20lifetime%20and%20browser%20context.%20See%20%5BBetter%20Auth%20session%20management%20docs%5D%28https%3A//github.com/better-auth/better-auth/blob/91cea0d0a79e6009eccda62e43c39cb44ef59625/docs/content/docs/concepts/session-management.mdx%23L6-L350%29.%0A%0AAlso%2C%20with%20Next.js%2016%2C%20make%20sure%20you%20use%20the%20%60%22use%20cache%3A%20private%22%60%20directive%20for%20session-related%20routes/components%20to%20avoid%20issues%20with%20header%20caching%2C%20and%20consider%20using%20more%20specific%20middleware%20matchers%20%28like%20%60/dashboard%60%29%20instead%20of%20%60/%60%20for%20reliable%20session%20checks%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/2143%29.%0A%0AIf%20you%20initiate%20OAuth%20login%20server-side%2C%20set%20%60asResponse%3A%20true%60%20in%20%60signInWithOAuth2%60%20to%20ensure%20cookies%20are%20set%20correctly%20in%20the%20response%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/6535%29.%0A%0AFinally%2C%20double-check%20your%20cookie%20attributes%20%28%60sameSite%60%2C%20%60secure%60%2C%20%60httpOnly%60%2C%20%60domain%60%29%20for%20consistency%20between%20OAuth%20requests%20and%20callbacks%2C%20especially%20in%20development%20environments%20%5Bsource%5D%28https%3A//github.com/better-auth/better-auth/issues/5658%29.%0A%0AIf%20you%20need%20persistent%20sessions%2C%20update%20your%20config%20to%20use%20a%20database%20or%20enable%20cookie%20caching.%20If%20you%20want%20stateless%20sessions%2C%20configure%20%60session.cookieCache%60%20as%20shown%20in%20the%20docs.)&nbsp;[![Join Discord](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&label=)](https://go.dosu.dev/discord-bot)&nbsp;[![Share on X](https://img.shields.io/badge/X-share-black)](https://twitter.com/intent/tweet?text=%40dosu_ai%20helped%20me%20solve%20this%20issue!&url=https%3A//github.com/better-auth/better-auth/issues/6853)
Author
Owner

@Adityakk9031 commented on GitHub (Dec 19, 2025):

@better-auth-agent propose a fix

<!-- gh-comment-id:3675376060 --> @Adityakk9031 commented on GitHub (Dec 19, 2025): @better-auth-agent propose a fix
Author
Owner

@better-auth-agent[bot] commented on GitHub (Dec 19, 2025):

It seems you're experiencing a server error with your NextJS application while using Better Auth 1.4.7. This kind of issue is often related to routing or session management, especially after restarting the server.

Here are some steps you can take to troubleshoot:

  1. Verify Session Management: Ensure that your session cookies are being maintained correctly before and after you shut down and restart your application. In your proxy.ts, check if the session cookie is preserved and properly retrieved after the restart.

  2. Middleware Setup: Ensure that your middleware setup in proxy.ts is correct. As you've set a matcher for the root route, make sure that your authentication handling works as intended upon re-visiting the application.

  3. Review Errors in Console/Logs: Pay attention to the console or logs after the restart. Any specific error messages might give you a clue about what is failing.

  4. Check Configuration: Ensure your configuration for next-cookies and the generic-oauth plugin aligns with the documentation for Better Auth 1.4.7.

  5. Update Dependencies: If you haven’t already, consider updating to the latest versions of both NextJS and Better Auth as fixes may have been introduced for known issues.

If problems persist, please consider tagging Beka (@bekacru) or Max (@ping__) for their insights on these issues. They may offer more tailored advice based on their experience and further investigation into any related issues that have been raised recently.

Is there anything specific in the setup or configuration you would like to focus on troubleshooting further?

DiagramDiscordGitHub

Diagram Join Star

<!-- gh-comment-id:3675377021 --> @better-auth-agent[bot] commented on GitHub (Dec 19, 2025): It seems you're experiencing a server error with your NextJS application while using Better Auth 1.4.7. This kind of issue is often related to routing or session management, especially after restarting the server. Here are some steps you can take to troubleshoot: 1. **Verify Session Management**: Ensure that your session cookies are being maintained correctly before and after you shut down and restart your application. In your `proxy.ts`, check if the session cookie is preserved and properly retrieved after the restart. 2. **Middleware Setup**: Ensure that your middleware setup in `proxy.ts` is correct. As you've set a matcher for the root route, make sure that your authentication handling works as intended upon re-visiting the application. 3. **Review Errors in Console/Logs**: Pay attention to the console or logs after the restart. Any specific error messages might give you a clue about what is failing. 4. **Check Configuration**: Ensure your configuration for `next-cookies` and the `generic-oauth` plugin aligns with the documentation for Better Auth 1.4.7. 5. **Update Dependencies**: If you haven’t already, consider updating to the latest versions of both NextJS and Better Auth as fixes may have been introduced for known issues. If problems persist, please consider tagging Beka (@bekacru) or Max (@ping__) for their insights on these issues. They may offer more tailored advice based on their experience and further investigation into any related issues that have been raised recently. Is there anything specific in the setup or configuration you would like to focus on troubleshooting further? <!-- bot:webhook reply v1 --> [Diagram](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) • [Discord](https://discord.gg/fG2XXEuQX3) • [GitHub](https://github.com/Skyvern-AI/Skyvern) [![Diagram](https://img.shields.io/badge/Diagram-2b3137?style=flat-square)](https://repodiagrams.s3.eu-north-1.amazonaws.com/skyvern_ultra_detailed_interactive.html) [![Join](https://img.shields.io/badge/join-5865F2?logo=discord&logoColor=white&style=flat-square)](https://discord.gg/fG2XXEuQX3) [![Star](https://img.shields.io/badge/star-181717?logo=github&logoColor=white&style=flat-square)](https://github.com/Skyvern-AI/Skyvern)
Author
Owner

@himself65 commented on GitHub (Dec 23, 2025):

can you try to log the cookie to see if it exists?

<!-- gh-comment-id:3685874999 --> @himself65 commented on GitHub (Dec 23, 2025): can you try to log the cookie to see if it exists?
Author
Owner

@damonshen17 commented on GitHub (Dec 24, 2025):

Additional findings - Root cause identified

I encountered a similar issue with Next.js 16 and getSessionCookie. After debugging, I found the root cause:

The Problem

In getSessionCookie, there's this logic:

const headers = "headers" in request ? request.headers : request;
const cookies = headers.get("cookie");

When passing Next.js 16's ReadonlyHeaders (from await headers() in server components), the check "headers" in request returns true because ReadonlyHeaders has inherited properties that match. This causes the function to try request.headers instead of using the ReadonlyHeaders object directly, resulting in:

TypeError: headers.get is not a function

Workaround

I fixed this by manually parsing the cookie header instead of using getSessionCookie:

const reqHeaders = await headers();
const cookieHeader = reqHeaders.get("cookie");

const cookiePrefix = env.COOKIE_PREFIX ?? "better-auth";
const sessionCookieName = `${cookiePrefix}.session_token`;
const secureCookieName = `__Secure-${sessionCookieName}`;

let sessionToken: string | null = null;
if (cookieHeader) {
  const cookies = cookieHeader.split("; ");
  for (const cookie of cookies) {
    const [name, ...valueParts] = cookie.split("=");
    if (name === sessionCookieName || name === secureCookieName) {
      sessionToken = valueParts.join("=");
      break;
    }
  }
}

Suggested Fix

The getSessionCookie function should check for Request objects more specifically, perhaps using instanceof Request instead of "headers" in request, or handle Next.js's ReadonlyHeaders type explicitly.

Environment:

  • better-auth: 1.4.0-beta.9
  • Next.js: 16.0.7
  • Using getSessionCookie in server components with await headers()
<!-- gh-comment-id:3690299673 --> @damonshen17 commented on GitHub (Dec 24, 2025): ## Additional findings - Root cause identified I encountered a similar issue with Next.js 16 and `getSessionCookie`. After debugging, I found the **root cause**: ### The Problem In `getSessionCookie`, there's this logic: ```typescript const headers = "headers" in request ? request.headers : request; const cookies = headers.get("cookie"); ``` When passing Next.js 16's `ReadonlyHeaders` (from `await headers()` in server components), the check `"headers" in request` returns `true` because `ReadonlyHeaders` has inherited properties that match. This causes the function to try `request.headers` instead of using the `ReadonlyHeaders` object directly, resulting in: ``` TypeError: headers.get is not a function ``` ### Workaround I fixed this by manually parsing the cookie header instead of using `getSessionCookie`: ```typescript const reqHeaders = await headers(); const cookieHeader = reqHeaders.get("cookie"); const cookiePrefix = env.COOKIE_PREFIX ?? "better-auth"; const sessionCookieName = `${cookiePrefix}.session_token`; const secureCookieName = `__Secure-${sessionCookieName}`; let sessionToken: string | null = null; if (cookieHeader) { const cookies = cookieHeader.split("; "); for (const cookie of cookies) { const [name, ...valueParts] = cookie.split("="); if (name === sessionCookieName || name === secureCookieName) { sessionToken = valueParts.join("="); break; } } } ``` ### Suggested Fix The `getSessionCookie` function should check for `Request` objects more specifically, perhaps using `instanceof Request` instead of `"headers" in request`, or handle Next.js's `ReadonlyHeaders` type explicitly. **Environment:** - better-auth: 1.4.0-beta.9 - Next.js: 16.0.7 - Using `getSessionCookie` in server components with `await headers()`
Author
Owner

@dosubot[bot] commented on GitHub (Mar 25, 2026):

Hi, @niassuh1. I'm Dosu, and I'm helping the better-auth team manage their backlog and am marking this issue as stale.

Issue Summary:

  • You reported a server error in NextJS 16.0.10 with Better Auth 1.4.7 after login via Keycloak and app restart, expecting to reach the "/" page but encountering an error.
  • The issue likely arises because Better Auth sessions do not persist across server restarts without persistent storage like a database or Redis.
  • A workaround involving manual cookie parsing was proposed due to Next.js 16's ReadonlyHeaders causing a TypeError in getSessionCookie.
  • The community has suggested verifying session cookies, middleware setup, and configuration.
  • Maintainers @bekacru and @ping__ have been tagged for further insights but no resolution has been posted yet.

Next Steps:

  • Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open.
  • If I do not hear back within 7 days, I will automatically close this issue.

Thank you for your understanding and contribution!

<!-- gh-comment-id:4127834277 --> @dosubot[bot] commented on GitHub (Mar 25, 2026): Hi, @niassuh1. I'm [Dosu](https://dosu.dev), and I'm helping the better-auth team manage their backlog and am marking this issue as stale. **Issue Summary:** - You reported a server error in NextJS 16.0.10 with Better Auth 1.4.7 after login via Keycloak and app restart, expecting to reach the "/" page but encountering an error. - The issue likely arises because Better Auth sessions do not persist across server restarts without persistent storage like a database or Redis. - A workaround involving manual cookie parsing was proposed due to Next.js 16's ReadonlyHeaders causing a TypeError in getSessionCookie. - The community has suggested verifying session cookies, middleware setup, and configuration. - Maintainers @bekacru and @ping__ have been tagged for further insights but no resolution has been posted yet. **Next Steps:** - Please let me know if this issue is still relevant with the latest version of better-auth by commenting here to keep the discussion open. - If I do not hear back within 7 days, I will automatically close this issue. Thank you for your understanding and contribution!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#19285