HTTP basic auth middleware for NestJS
npm install nestjs-basic-authHTTP basic auth middleware for NestJS.
By using this package, you can place a basic auth on any address in the NestJS framework to prevent unauthorized access.
For example, you can set a username and password to the Swagger document.
``shell`
npm install nestjs-basic-auth
or
`shell`
yarn add nestjs-basic-auth
The module exports a function that, when called with an options object, returns the middleware.
`js
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { basicAuth } from 'nestjs-basic-auth';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.use(
['/docs'],
basicAuth({
challenge: true,
users: { admin: 'password' },
}),
);
await app.listen(3000);
}
bootstrap();
``