({ user }: RequestHandlerParams)
| 14 | } |
| 15 | |
| 16 | async function post({ user }: RequestHandlerParams) { |
| 17 | const isMultiFactorAuthEnabled = await AppConfig.isMultiFactorAuthEnabled(); |
| 18 | |
| 19 | if (!isMultiFactorAuthEnabled) { |
| 20 | const responseBody: ResponseBody = { |
| 21 | success: false, |
| 22 | error: 'Multi-factor authentication is not enabled on this server', |
| 23 | }; |
| 24 | |
| 25 | return new Response(JSON.stringify(responseBody), { status: 403 }); |
| 26 | } |
| 27 | |
| 28 | const methodId = MultiFactorAuthModel.generateMethodId(); |
| 29 | const setup = await EmailModel.createMethod(methodId, 'Email', user!); |
| 30 | |
| 31 | if (!user!.extra.multi_factor_auth_methods) { |
| 32 | user!.extra.multi_factor_auth_methods = []; |
| 33 | } |
| 34 | |
| 35 | user!.extra.multi_factor_auth_methods.push(setup.method); |
| 36 | |
| 37 | await UserModel.update(user!); |
| 38 | |
| 39 | const responseData: ResponseBody = { |
| 40 | success: true, |
| 41 | data: { |
| 42 | methodId: setup.method.id, |
| 43 | }, |
| 44 | }; |
| 45 | |
| 46 | return new Response(JSON.stringify(responseData)); |
| 47 | } |
| 48 | |
| 49 | export default page({ |
| 50 | post, |
nothing calls this directly
no test coverage detected