MCPcopy Create free account
hub / github.com/bewcloud/bewcloud / post

Function post

pages/api/auth/multi-factor/email/setup.ts:16–47  ·  view source on GitHub ↗
({ user }: RequestHandlerParams)

Source from the content-addressed store, hash-verified

14}
15
16async 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
49export default page({
50 post,

Callers

nothing calls this directly

Calls 4

generateMethodIdMethod · 0.80
createMethodMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected