Skip to content

context.session is accessed on prerendered public routes, breaking export const prerender = true #399

@hayatosc

Description

@hayatosc

Description

When using EmDash with Astro, setting export const prerender = true on a public page causes runtime errors because EmDash middleware accesses context.session even on prerendered routes.

Problem

EmDash middleware reads context.session on public routes without checking whether the route is prerendered.

const sessionUser = await context.session?.get("user");

const isAuthenticated = !!(await context.session?.get("user"));

Fix

On public route, avoid any context.session access when context.isPrerendered is true.

for example:

const sessionUser = context.isPrerendered
    ? null
    : await context.session?.get("user");

Steps to reproduce

  1. Create an EmDash site with output: "server" and the EmDash integration enabled.
  2. In a public page such as src/pages/index.astro, add:
export const prerender = true
  1. Start dev server
  2. Go http://localhost:4321

Environment

  • emdash: 0.1.0
  • astro: 6.1.3
  • @astrojs/cloudflare: 13.1.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions