Product Docs Pricing Changelog
Start free Sign in
Docs / Frameworks / Astro

Astro

Service-key calls only run in .astro frontmatter or src/pages/api/* endpoints. Client islands either talk to your endpoints or import a browser-only client. (Needs an SSR adapter — e.g. @astrojs/cloudflare — so frontmatter runs on the server per request.)

// src/lib/flarelink.ts — server import { createFlarelink } from "@flarelink/client" export function flarelinkFor(request: Request) { return createFlarelink({ url: import.meta.env.PUBLIC_FLARELINK_AUTH_URL, serviceKey: import.meta.env.FLARELINK_SERVICE_KEY, cookies: () => request.headers.get("cookie") ?? "", }) }

Protect a route

Resolve the user in frontmatter and return Astro.redirect(...) before rendering when there's no session.

--- // src/pages/dashboard.astro import { flarelinkFor } from "../lib/flarelink" const flarelink = flarelinkFor(Astro.request) const me = await flarelink.auth.getMe() if (!me) return Astro.redirect("/login") const { rows: posts } = await flarelink .from("posts") .where({ author_id: me.id }) --- <ul>{posts.map(p => <li>{p.title}</li>)}</ul>

Same rule in src/pages/api/* endpoints: call getMe(), return a 401 on null, scope queries to me.id.

# .env PUBLIC_FLARELINK_AUTH_URL=https://myapp-auth.your-subdomain.workers.dev FLARELINK_SERVICE_KEY=flarelink_sk_…
Something unclear or missing? [email protected] llms-full.txt ↗