Install and setup Kilpi
Install Kilpi and setup your Kilpi instance by following the quickstart guide.
export const Kilpi = createKilpi({ ... })
Handle unauthorized errors from .assert()
The .assert()
method throws an error when authorization is denied.
Since Nest.js supports throwing HTTP exceptions, handling unauthorized exceptions is easiest with a global onUnauthorizedAssert
handler.
export const Kilpi = createKilpi({ // ... async onUnauthorizedAssert(decision) { // Optionally customize behavior based on the decision switch (decision.reason) { ... }
// By default, throw a HTTP 403 Forbidden exception throw new HttpException(decision.message, HttpStatus.FORBIDDEN); }})