# Two-Factor Authentication

Two-factor authentication (2FA) using Time-based One-Time Passwords (TOTP) adds an extra layer of security to user authentication.&#x20;

These codes expire after a short period, making it difficult for attackers to gain unauthorized access even if passwords are compromised.&#x20;

You can see the implementation below

<https://github.com/madewithnovel/novel/blob/main/packages/novel/auth.js#L142>

<https://github.com/madewithnovel/novel/blob/main/app/api/internal/v1/auth-mfa/index.ts>

## Confugration

You will need to set up the `mfa` setting to true in `config/auth.js`.

{% code title="config/auth.js" lineNumbers="true" %}

```typescript
export default {
	/**
	 * Allows the use of MFA for users in the application.
	 */
	mfa: true,
}
```

{% endcode %}

## API

You can use `/auth/password/mfa`  to perform a Magic Link flow.

{% openapi src="/files/hpwpvNShDhKbLsaTo1Zx" path="/auth/{strategy}/mfa" method="post" %}
[openapi.json](https://1230772123-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FgjPdizpdFKu8XPFFoBRj%2Fuploads%2FBSDtmhW0VYiMTiBBhApj%2Fopenapi.json?alt=media\&token=6bf741e5-9e70-4443-9b94-5c062e5c697c)
{% endopenapi %}

## Changelog

* 2024-12-20 - Initial Documentation


---

# Agent Instructions: 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://docs.novel.dev/novel-server/authentication/two-factor-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.
