Radon
Framework Integrations

NestJS

Mount Radon in a NestJS app — a catch-all controller handler plus a CanActivate guard. A Radon Pro feature.

Radon Pro

The NestJS integration is a Pro feature and requires a license. See Radon Pro.

NestJS runs on Express (or Fastify) under the hood, so Radon plugs in as a (req, res) handler you call from a catch-all controller, plus a CanActivate guard for your own routes.

1. Mount the auth routes

auth.controller.ts
import { All, Controller, Req, Res } from "@nestjs/common";
import { radonNestHandler } from "@radonsdk/auth/pro/integrations/nestjs";
import { auth } from "./auth";

const handler = radonNestHandler(auth, { basePath: "/api/auth" });

@Controller("api/auth")
export class AuthController {
  @All("*")
  handle(@Req() req: any, @Res() res: any) {
    return handler(req, res);
  }
}

Init the license on boot

Because this is a Pro integration, call await auth.init() during app bootstrap (e.g. in main.ts) so the license is verified once.

2. Guard your own routes

createRadonAuthGuard(auth) returns a CanActivate guard class. It requires a valid session and attaches the user to request.radonUser.

some.controller.ts
import { Controller, Get, Req, UseGuards } from "@nestjs/common";
import { createRadonAuthGuard } from "@radonsdk/auth/pro/integrations/nestjs";
import { auth } from "./auth";

const RadonAuthGuard = createRadonAuthGuard(auth);

@Controller()
export class MeController {
  @UseGuards(RadonAuthGuard)
  @Get("me")
  me(@Req() req: any) {
    return req.radonUser;
  }
}

Next steps

On this page