Docs / Frameworks / Remix
Remix
Server-only file is conventionally .server.ts — Remix won't bundle it for the browser.
// app/flarelink.server.ts
import { createFlarelink } from "@flarelink/client"
export function flarelinkFor(request: Request) {
return createFlarelink({
url: process.env.FLARELINK_AUTH_URL!,
serviceKey: process.env.FLARELINK_SERVICE_KEY!,
cookies: () => request.headers.get("cookie") ?? "",
})
}
Protect a route
Resolve the user at the top of the loader and throw redirect(...) when there's no session. A thrown redirect short-circuits the loader, so nothing below it runs for signed-out users.
// app/routes/dashboard.tsx
import { redirect } from "@remix-run/node"
import { flarelinkFor } from "~/flarelink.server"
export const loader = async ({ request }) => {
const flarelink = flarelinkFor(request)
const me = await flarelink.auth.getMe()
if (!me) throw redirect("/login")
const { rows: posts } = await flarelink
.from("posts")
.where({ author_id: me.id })
return { posts, me }
}
Scope every query to me.id server-side. Reuse flarelinkFor(request) in actions to authorize mutations the same way.
# .env
FLARELINK_AUTH_URL=https://myapp-auth.your-subdomain.workers.dev
FLARELINK_SERVICE_KEY=flarelink_sk_…
Something unclear or missing? hello@flarelink.dev
llms-full.txt ↗