Raw
1 ---
2 sidebar_label: "Module Options"
3 ---
4
5 import { Table } from "docs-ui"
6
7 export const metadata = {
8 title: `Auth Module Options`,
9 }
10
11 # {metadata.title}
12
13 In this guide, you'll learn about the options of the Auth Module.
14
15 ## providers
16
17 The `providers` option is an array of auth module providers.
18
19 When the Medusa application starts, these providers are registered and can be used to handle authentication.
20
21 <Note title="Tip">
22
23 By default, the `emailpass` provider is registered to authenticate customers and admin users.
24
25 </Note>
26
27 For example:
28
29 ```ts title="medusa-config.ts"
30 import { Modules, ContainerRegistrationKeys } from "@medusajs/framework/utils"
31
32 // ...
33
34 module.exports = defineConfig({
35 // ...
36 modules: [
37 {
38 resolve: "@medusajs/medusa/auth",
39 dependencies: [Modules.CACHE, ContainerRegistrationKeys.LOGGER],
40 options: {
41 mfa: {
42 encryption_key: process.env.AUTH_MFA_ENCRYPTION_KEY,
43 },
44 providers: [
45 {
46 resolve: "@medusajs/medusa/auth-emailpass",
47 id: "emailpass",
48 options: {
49 // provider options...
50 },
51 },
52 ],
53 },
54 },
55 ],
56 })
57 ```
58
59 The `providers` option is an array of objects that accept the following properties:
60
61 - `resolve`: A string indicating the package name of the module provider or the path to it relative to the `src` directory.
62 - `id`: A string indicating the provider's unique name or ID.
63 - `options`: An optional object of the module provider's options.
64
65 ---
66
67 ## Auth CORS
68
69 The Medusa application's authentication API routes are defined under the `/auth` prefix that requires setting the `authCors` property of the `http` configuration.
70
71 By default, the Medusa application you created will have an `AUTH_CORS` environment variable, which is used as the value of `authCors`.
72
73 Refer to [Medusa's configuration guide](!docs!/learn/configurations/medusa-config#httpauthCors) to learn more about the `authCors` configuration.
74
75 ---
76
77 ## mfa
78
79 The `mfa` option configures multi-factor authentication (MFA) settings for the Auth Module.
80
81 When passing any options to the Auth Module, you must set the `mfa.encryption_key` option. This option is set by default to the `AUTH_MFA_ENCRYPTION_KEY` environment variable. If you created your Medusa application after v2.15.5, this environment variable is already set in your `.env` file. If not, make sure to set it to a random string.
82
83 <Note>
84
85 This feature is available in [Medusa v2.15.5](!docs!/learn/update) and above.
86
87 </Note>
88
89 For example:
90
91 ```ts title="medusa-config.ts"
92 import { Modules, ContainerRegistrationKeys } from "@medusajs/framework/utils"
93
94 // ...
95
96 module.exports = defineConfig({
97 // ...
98 modules: [
99 {
100 resolve: "@medusajs/medusa/auth",
101 dependencies: [Modules.CACHE, ContainerRegistrationKeys.LOGGER],
102 options: {
103 mfa: {
104 encryption_key: process.env.AUTH_MFA_ENCRYPTION_KEY,
105 disable_policy: "challenge",
106 },
107 },
108 },
109 ],
110 })
111 ```
112
113 The `mfa` option accepts the following properties:
114
115 - `encryption_key`: A string indicating the encryption key used for MFA. This is required and should be set to the `AUTH_MFA_ENCRYPTION_KEY` environment variable.
116 - If you don't set the `mfa.encryption_key` option, you'll get a "MFA encryption key is required to use MFA methods" error whenever trying to enroll or verify an MFA factor.
117 - `recovery_code_count`: An optional number indicating the number of recovery codes to generate for each user. The default is `10`.
118 - `challenge_ttl_seconds`: An optional number indicating the time-to-live (TTL) of MFA challenges in seconds. The default is `300` seconds (5 minutes).
119 - `challenge_max_attempts`: An optional number indicating the maximum number of failed attempts allowed for an MFA challenge. The default is `5`.
120 - `disable_policy`: A string indicating the policy for disabling MFA factors. Can be either:
121 - `"session"` (default): Only requires a valid session to disable an MFA factor.
122 - `"challenge"`: Requires MFA challenge verification to disable an MFA factor.
123 - `providers`: An optional array of MFA providers to use. These are registered alongside, and can override, the default `totp` and `recovery_code` providers. Each object in the array accepts the following properties:
124 - `resolve`: A string indicating the package name of the MFA provider or the path to it relative to the `src` directory.
125 - `id`: A string indicating the MFA provider's unique name or ID. The ID is prefixed with `mfa_`. If not provided, the `identifier` static property of the provider's service is used.
126 - `options`: An optional object of the MFA provider's options.
127
128 ---
129
130 ## authMethodsPerActor Configuration
131
132 The Medusa application's configuration accept an `authMethodsPerActor` configuration which restricts the allowed auth providers used with an actor type.
133
134 Learn more about the `authMethodsPerActor` configuration in [this guide](../auth-providers/page.mdx#configure-allowed-auth-providers-of-actor-types).