> For the complete documentation index, see [llms.txt](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/extra-module-3-openapi-specification/enabling-authentication.md).

# Enabling authentication

The next improvement will be quite simple. We'll allow authentication in the Swagger UI, and also enable it for all the routes automatically. Let's then go back to the <mark style="color:purple;">main</mark> file.

To enable authentication, add the following just before the <mark style="color:blue;">`setVersion()`</mark> call.

```typescript
.addBearerAuth()
```

And to enable it for all the routes, also add after it:

```typescript
.addSecurityRequirements('bearer')
```

With this, we can access protected routes in the Swagger UI.

<mark style="color:green;">**Commit**</mark> - Enabling bearer auth in swagger


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kinesis-school-of-programming.gitbook.io/nestjs-unleashed/extra-module-3-openapi-specification/enabling-authentication.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
