Regression: Angular prerendering fails with authClient.getSession() after v1.3.8 #2054

Closed
opened 2026-03-13 09:23:21 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @rujorgensen on GitHub (Oct 1, 2025).

Is this suited for github?

  • Yes, this is suited for github

To Reproduce

Description

There is a regression between better-auth v1.3.7 and v1.3.8+ (latest tested: v1.3.24).

When prerendering routes that depend on authClient.getSession(), the build fails.

Project Setup

Prerendering setup: apps/frontend/src/app/app.routes.server.ts

Route definitions: apps/frontend/src/app/app.routes.ts

Steps to reproduce:

See reproduction at: https://github.com/rujorgensen/better-auth-repro

  • Install dependencies bun install
  • Build nx run ngx-better-auth:build:production Works with better-auth@1.3.7
  • Update better auth bun add better-auth@1.3.8 (also tested up to better-auth@1.3.24)
  • Build again nx run ngx-better-auth:build:production Error occurs during prerendering

Current vs. Expected behavior

Expected Behavior

Prerendering should succeed as in v1.3.7.

Actual Behavior

With v1.3.8+, prerendering fails when calling authClient.getSession() inside route setup.

Image

What version of Better Auth are you using?

1.3.8 ... 1.3.24

System info

{
  "system": {
    "platform": "linux",
    "arch": "x64",
    "version": "#1 SMP PREEMPT_DYNAMIC Thu Jun  5 18:30:46 UTC 2025",
    "release": "6.6.87.2-microsoft-standard-WSL2",
    "cpuCount": 20,
    "cpuModel": "12th Gen Intel(R) Core(TM) i7-12800H",
    "totalMemory": "15.45 GB",
    "freeMemory": "12.16 GB"
  },
  "node": {
    "version": "v22.15.1",
    "env": "development"
  },
  "packageManager": {
    "name": "npm",
    "version": "10.9.2"
  },
  "frameworks": null,
  "databases": [
    {
      "name": "@prisma/client",
      "version": "^6.16.3"
    }
  ],
  "betterAuth": {
    "version": "1.3.7",
    "config": null
  }
}

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

Client

Auth config (if applicable)

export const authClient = createAuthClient();

Additional context

In my case, it doesn’t really make sense to prerender a page behind login.

However, it’s unexpected that the same build passed one day and failed the next after a patch dependency update.

The vague error could also stem from Angular’s prerendering pipeline, but the regression aligns with the version change in better-auth.

Originally created by @rujorgensen on GitHub (Oct 1, 2025). ### Is this suited for github? - [x] Yes, this is suited for github ### To Reproduce # Description There is a regression between better-auth v1.3.7 and v1.3.8+ (latest tested: v1.3.24). When prerendering routes that depend on authClient.getSession(), the build fails. # Project Setup Prerendering setup: apps/frontend/src/app/app.routes.server.ts Route definitions: apps/frontend/src/app/app.routes.ts # Steps to reproduce: See reproduction at: https://github.com/rujorgensen/better-auth-repro - Install dependencies `bun install` - Build `nx run ngx-better-auth:build:production` ✅ Works with better-auth@1.3.7 - Update better auth `bun add better-auth@1.3.8` (also tested up to better-auth@1.3.24) - Build again `nx run ngx-better-auth:build:production` ❌ Error occurs during prerendering ### Current vs. Expected behavior # Expected Behavior Prerendering should succeed as in v1.3.7. # Actual Behavior With v1.3.8+, prerendering fails when calling authClient.getSession() inside route setup. <img width="1434" height="1078" alt="Image" src="https://github.com/user-attachments/assets/c4819a2b-4ee1-40ae-8c95-8b01f962aec0" /> ### What version of Better Auth are you using? 1.3.8 ... 1.3.24 ### System info ```bash { "system": { "platform": "linux", "arch": "x64", "version": "#1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025", "release": "6.6.87.2-microsoft-standard-WSL2", "cpuCount": 20, "cpuModel": "12th Gen Intel(R) Core(TM) i7-12800H", "totalMemory": "15.45 GB", "freeMemory": "12.16 GB" }, "node": { "version": "v22.15.1", "env": "development" }, "packageManager": { "name": "npm", "version": "10.9.2" }, "frameworks": null, "databases": [ { "name": "@prisma/client", "version": "^6.16.3" } ], "betterAuth": { "version": "1.3.7", "config": null } } ``` ### Which area(s) are affected? (Select all that apply) Client ### Auth config (if applicable) ```typescript export const authClient = createAuthClient(); ``` ### Additional context In my case, it doesn’t really make sense to prerender a page behind login. However, it’s unexpected that the same build passed one day and failed the next after a patch dependency update. The vague error could also stem from Angular’s prerendering pipeline, but the regression aligns with the version change in better-auth.
GiteaMirror added the bug label 2026-03-13 09:23:21 -05:00
Author
Owner

@dosubot[bot] commented on GitHub (Oct 1, 2025):

This is a confirmed regression in Better Auth starting with v1.3.8 that affects Angular prerendering when using authClient.getSession(). The root cause is a change in how the client detects and handles server-side environments, which now requires more explicit configuration for SSR/prerendering contexts. This has led to similar issues in other SSR frameworks, where session retrieval fails or returns null due to absolute URL usage or missing headers/cookies during server-side requests [source].

Key points and workarounds:

  • authClient.getSession() is intended for client-side use. For server-side (including prerendering), use auth.api.getSession() and pass the correct headers (like cookies or API keys) [source].
  • If you must use the client in SSR/prerendering, you may need to wrap or customize the fetch implementation to ensure cookies are forwarded and only relative URLs are used, as absolute URLs can cause cookies to be dropped in SSR environments [source].
  • There are ongoing issues and discussions tracking this regression and related SSR session problems: issue #4722 and related threads.
  • If you need a quick workaround, consider downgrading to v1.3.7, which does not have this regression.

If you want to adapt your code for SSR/prerendering, try switching to auth.api.getSession() on the server, or ensure your fetch implementation strips the origin from URLs and forwards cookies correctly. This pattern has worked for Nuxt and Next.js SSR and should be adaptable to Angular's prerendering pipeline.

To reply, just mention @dosu.


How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other  Chat with Dosu Join Discord Share on X

@dosubot[bot] commented on GitHub (Oct 1, 2025): <!-- Answer --> This is a confirmed regression in Better Auth starting with v1.3.8 that affects Angular prerendering when using `authClient.getSession()`. The root cause is a change in how the client detects and handles server-side environments, which now requires more explicit configuration for SSR/prerendering contexts. This has led to similar issues in other SSR frameworks, where session retrieval fails or returns null due to absolute URL usage or missing headers/cookies during server-side requests [[source]](https://github.com/better-auth/better-auth/issues/4722#issuecomment-3316072301). Key points and workarounds: - `authClient.getSession()` is intended for client-side use. For server-side (including prerendering), use `auth.api.getSession()` and pass the correct headers (like cookies or API keys) [[source]](https://github.com/better-auth/better-auth/issues/3588). - If you must use the client in SSR/prerendering, you may need to wrap or customize the fetch implementation to ensure cookies are forwarded and only relative URLs are used, as absolute URLs can cause cookies to be dropped in SSR environments [[source]](https://github.com/better-auth/better-auth/issues/4722). - There are ongoing issues and discussions tracking this regression and related SSR session problems: [issue #4722](https://github.com/better-auth/better-auth/issues/4722) and related threads. - If you need a quick workaround, consider downgrading to v1.3.7, which does not have this regression. If you want to adapt your code for SSR/prerendering, try switching to `auth.api.getSession()` on the server, or ensure your fetch implementation strips the origin from URLs and forwards cookies correctly. This pattern has worked for Nuxt and Next.js SSR and should be adaptable to Angular's prerendering pipeline. <!-- 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/28b85e5e-a0d9-419b-be1e-782236f22dbe?feedback_type=great_response) | [Irrelevant](https://app.dosu.dev/response-feedback/28b85e5e-a0d9-419b-be1e-782236f22dbe?feedback_type=irrelevant_answer) | [Incorrect](https://app.dosu.dev/response-feedback/28b85e5e-a0d9-419b-be1e-782236f22dbe?feedback_type=incorrect_sources) | [Verbose](https://app.dosu.dev/response-feedback/28b85e5e-a0d9-419b-be1e-782236f22dbe?feedback_type=too_verbose) | [Hallucination](https://app.dosu.dev/response-feedback/28b85e5e-a0d9-419b-be1e-782236f22dbe?feedback_type=hallucination) | [Report 🐛](https://app.dosu.dev/response-feedback/28b85e5e-a0d9-419b-be1e-782236f22dbe?feedback_type=bug_report) | [Other](https://app.dosu.dev/response-feedback/28b85e5e-a0d9-419b-be1e-782236f22dbe?feedback_type=other)</sup>&nbsp;&nbsp;[![Chat with Dosu](https://dosu.dev/dosu-chat-badge.svg)](https://app.dosu.dev/cdda13d9-dd27-4d31-b09a-5d8bec92de21/ask?utm_source=github)&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/5020)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/better-auth#2054