Auth Decorator
Last updated
Last updated
In the initial configuration of Swagger that was done in the Setup Section, the following line was added:
With this line we indicate that we will use a bearer token to authenticate the user, but for this to work you must use the @ApiBearerAuth decorator.
Example:
You must declare the @ApiBearerAuth() property so that Swagger can read your access token. If you don't put this decorator in your controller, the authentication will not work.
If you want to add another authentication method, you can do it in the generated configuration in src/main.ts
file, and also add your decorators in the controllers where you want to use these authentication methods.
In this configuration you have 3 authentication methods:
Bearer Token.
Api Key.
Basic Auth.
Example:
Then, when you want to authenticate to the Swagger interface, you can choose any of these methods. This is how it would look: