Nest.js
Install Kilpi for Nest.js
Ensure you have setup Kilpi using the quickstart guide before proceeding.
Installing Kilpi for Nest.js is as easy as providing Kilpi scope within a middleware. You do not need any plugins. We also recommend to set an onUnauthorized
handler to throw an UnauthorizedException with a 403 status code.
import { Request, Response, NextFunction } from 'express';
function kilpiMiddleware(req: Request, res: Response, next: NextFunction) { Kilpi.runInScope(async () => { Kilpi.onUnauthorized(() => { throw new ForbiddenException(); })
next(); })};
app.use(kilpiMiddleware)