Framework Integrations
Koa
Mount Radon as Koa middleware — all auth routes plus a requireAuth guard that sets ctx.state.user. A Radon Pro feature.
Radon Pro
The Koa integration is a Pro feature and requires a license. See Radon Pro.
Radon plugs into Koa as middleware. Mount radonKoa(auth) (typically with
koa-mount) and guard your own routes with requireAuth.
Body parsing is required
Radon reads ctx.request.body on POST routes, so a body parser like
koa-bodyparser must run before the auth middleware.
1. Mount the auth routes
import Koa from "koa";
import bodyParser from "koa-bodyparser";
import mount from "koa-mount";
import { radonKoa } from "@radonsdk/auth/pro/integrations/koa";
import { auth } from "./auth";
const app = new Koa();
app.use(bodyParser());
// Serves every auth route under /api/auth.
app.use(mount("/api/auth", radonKoa(auth)));
app.listen(3000);2. Guard your own routes
requireAuth(auth) returns 401 for unauthenticated requests and sets
ctx.state.user (and ctx.state.userId) on success.
import Router from "@koa/router";
import { requireAuth } from "@radonsdk/auth/pro/integrations/koa";
const router = new Router();
router.get("/me", requireAuth(auth), (ctx) => {
ctx.body = ctx.state.user;
});
app.use(router.routes());