Radon
Framework Integrations

Astro

Mount Radon in Astro — a catch-all endpoint handler plus getUser for pages and middleware. A Radon Pro feature.

Radon Pro

The Astro integration is a Pro feature and requires a license. Your Astro app needs SSR (a server adapter), since auth runs server-side. See Radon Pro.

Astro endpoints speak Web Request/Response, so Radon mounts as a handler you re-export from a catch-all endpoint.

1. Mount the auth routes

src/pages/api/auth/[...radon].ts
import { radonAstro } from "@radonsdk/auth/pro/integrations/astro";
import { auth } from "../../../lib/auth";

const handle = radonAstro(auth, { basePath: "/api/auth" });

export const GET = ({ request }: { request: Request }) => handle(request);
export const POST = ({ request }: { request: Request }) => handle(request);

2. Read the user in a page

getUser(auth, request) returns the user or null.

src/pages/dashboard.astro
---
import { getUser } from "@radonsdk/auth/pro/integrations/astro";
import { auth } from "../lib/auth";

const user = await getUser(auth, Astro.request);
if (!user) return Astro.redirect("/signin");
---
<h1>Welcome, {user.email}</h1>

3. Populate Astro.locals.user in middleware

src/middleware.ts
import { defineMiddleware } from "astro:middleware";
import { getUser } from "@radonsdk/auth/pro/integrations/astro";
import { auth } from "./lib/auth";

export const onRequest = defineMiddleware(async (context, next) => {
  context.locals.user = await getUser(auth, context.request);
  return next();
});

Next steps

On this page