Skip to content

fix: read session cookie server-side for auth-aware nav - #21

Merged
makeitraina merged 1 commit into
mainfrom
claude/analytics-migration-gameplan-md1qrs
Aug 24, 2026
Merged

fix: read session cookie server-side for auth-aware nav#21
makeitraina merged 1 commit into
mainfrom
claude/analytics-migration-gameplan-md1qrs

Conversation

@makeitraina

Copy link
Copy Markdown
Member

What

Moves the current-portal-session cookie detection from a client-side document.cookie check to a server-side cookies() read in the root layout, matching the approach the old site used.

Why

The dashboard's session cookie is HttpOnly — JavaScript can't read it via document.cookie, which is why the previous PR (#16) didn't activate the auth-aware UI despite using the correct cookie name. The server-side cookies() API from next/headers can read HttpOnly cookies, so the layout now stamps data-authed="1" or data-authed="0" directly on <html> at render time.

What changes for visitors:

  • Signed in (has current-portal-session cookie): sees "Open Assembly" in the header, no Free tier on pricing, CTAs say "Add app to workspace" / "Open Assembly"
  • Signed out: sees "Book a demo" + "Log in" + "Get started" (unchanged from today)

Changes

src/lib/auth-script.ts

  • Updated SESSION_COOKIE comment to document that the cookie is HttpOnly and read server-side
  • Simplified AUTH_INIT_SCRIPT to only handle the ?authed=1|0 demo override — it no longer attempts to read document.cookie (which couldn't see the HttpOnly cookie anyway)
  • If no demo override is active, the script leaves the server-set data-authed attribute untouched

src/app/layout.tsx

  • Imports cookies from next/headers
  • Reads current-portal-session and sets data-authed on <html> server-side

Screenshots

No visual changes to any components — the auth-only / unauth-only CSS mechanism, nav markup, pricing grid, and AuthLink components are all unchanged. This fix just makes the detection actually work.

Testing

  • On staging/production (where the cookie is present): the nav should toggle automatically
  • On preview URLs: append ?authed=1 to any URL to simulate signed-in, ?authed=0 for signed-out, ?authed=clear to reset

Checklist

  • npm run build passes
  • Type-check passes (tsc --noEmit)
  • Tested on mobile and desktop
  • Preview deploy looks correct

Generated by Claude Code

The `current-portal-session` cookie is HttpOnly, so the client-side
`document.cookie` check never saw it. Move the detection to the root
layout using `cookies()` from `next/headers`, which can read HttpOnly
cookies, and stamp `data-authed` on `<html>` at render time — matching
the approach the old site used.
The client-side script is kept solely for the demo override
(`?authed=1` / `?authed=0`), which lets both states be previewed on
any URL including Vercel previews where the cookie isn't present.
@vercel

vercelBot commented Aug 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

ProjectDeploymentActionsUpdated (UTC)
assembly-studio-websiteReadyReadyPreviewAug 24, 2026 6:35pm

Request Review

@greptile-apps

Copy link
Copy Markdown

Greptile Summary

Moves the shared session-cookie check into the server-rendered root layout so HttpOnly cookies can select auth-aware navigation before paint.

  • Reads current-portal-session with cookies() and stamps the resulting state on the root HTML element.
  • Retains the pre-paint client script only for persisted preview/demo overrides.
  • Introduces a site-wide request-time rendering dependency that works against existing static and ISR route declarations.

Confidence Score: 4/5

The PR appears safe to merge functionally, but the root-level cookie read should be reconsidered or isolated to preserve the site's static and ISR rendering behavior.

The server-derived auth signal aligns with the existing CSS and hook consumers, while the only accepted concern is the non-blocking rendering and caching cost of introducing a request-bound API in the root layout.

Files Needing Attention: src/app/layout.tsx

Important Files Changed

FilenameOverview
src/app/layout.tsxAdds the server-side cookie read and root auth attribute, while also making the shared layout depend on request data.
src/lib/auth-script.tsRemoves the ineffective document-cookie check and preserves the existing pre-paint demo-override behavior.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
R[Incoming request] --> L[Root layout]
L --> C[Read HttpOnly session cookie]
C --> A[Set html data-authed]
A --> CSS[CSS selects auth UI variant]
A --> H[Client auth hook]
Q[Demo query or stored override] --> S[Pre-paint override script]
S --> A
Loading

Reviews (1): Last reviewed commit: "fix: read session cookie server-side for..." | Re-trigger Greptile

Comment threadsrc/app/layout.tsx
Comment on lines +131 to +132
const cookieStore = await cookies();
const isAuthed = !!cookieStore.get(SESSION_COOKIE)?.value;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2Root layout forces dynamic rendering

Calling the request-bound cookies() API in the shared root layout prevents routes beneath it from retaining their intended static or ISR rendering behavior, adding request-time work and conflicting with pages explicitly pinned to build-time generation.

Knowledge Base Used:Site shell and shared UI

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

@makeitraina
makeitraina merged commit ecec339 into mainAug 24, 2026
3 checks passed
@makeitraina
makeitraina deleted the claude/analytics-migration-gameplan-md1qrs branch August 24, 2026 18:59
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@makeitraina@claude