Product Docs Pricing Changelog
Start free Sign in
Docs / SDK reference / SSR & cookies

SSR: forwarding the session cookie

In server frameworks (Next.js, SvelteKit, Remix, …) the browser's session cookie isn't on the server fetch by default — so flarelink.auth.getMe() would return null from a route handler / loader even when the user is signed in. Pass a cookies function and the SDK does the rest:

// Next.js (App Router) import { cookies } from "next/headers" import { createFlarelink } from "@flarelink/client" const flarelink = createFlarelink({ url: process.env.FLARELINK_AUTH_URL!, serviceKey: process.env.FLARELINK_SERVICE_KEY!, cookies: () => cookies().toString(), }) // flarelink.auth.getMe() now returns the signed-in user from your route handler
// Anything with a Request — Remix, SvelteKit, Hono, Astro, … const flarelink = createFlarelink({ url, serviceKey, cookies: () => request.headers.get("cookie") ?? "", })

cookies is called per-request, so it's safe to define the client at module scope when your framework's cookie API is request-scoped. Pass a plain string instead of a function if cookies are static. No effect in the browser — credentials: 'include' already carries cookies there. Use fetch: for full control if you need it (e.g. tests).

If getMe() returns null on the server even though the user is signed in, you almost always forgot cookies — or the auth Worker is on a cross-site workers.dev URL and the browser never stored the cookie in the first place. The second case is a browser problem (Safari especially); see Cookies & Safari.

For the full per-framework wiring, jump to the framework quickstarts: Next.js · SvelteKit · Remix · Astro · Hono.

Something unclear or missing? [email protected] llms-full.txt ↗