Skip to main content

Installation

npm install keyport-nestjs

Setup and usage

1

Register the module

Import KeyPortModule and call forRoot inside the imports array of your root AppModule. Supply your API key directly or point to a config file:
imports: [
  KeyPortModule.forRoot({
    apiKey: process.env.KEYPORT_API_KEY!,
  }),
]
2

Protect a route

Add the @RequireLicense() decorator to any controller method to enforce license validation on that endpoint:
@RequireLicense()
@Get('protected')
getProtected(@License() license) {
  return license;
}
Use the @License() parameter decorator to access the validated license payload inside the handler.
@RequireLicense() acts as a guard. Requests without a valid license key are rejected before your handler runs.
Load your API key from an environment variable (process.env.KEYPORT_API_KEY) or the NestJS ConfigModule rather than embedding it in source code.