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

Function post

pages/api/auth/multi-factor/disable.ts:21–106  ·  view source on GitHub ↗
({ request, user }: RequestHandlerParams)

Source from the content-addressed store, hash-verified

19}
20
21async function post({ request, user }: RequestHandlerParams) {
22 const isMultiFactorAuthEnabled = await AppConfig.isMultiFactorAuthEnabled();
23
24 if (!isMultiFactorAuthEnabled) {
25 const responseBody: ResponseBody = {
26 success: false,
27 error: 'Multi-factor authentication is not enabled on this server',
28 };
29
30 return new Response(JSON.stringify(responseBody), { status: 403 });
31 }
32
33 const body = await request.clone().json() as RequestBody;
34 const { methodId, password, disableAll } = body;
35
36 if (!password) {
37 const responseBody: ResponseBody = {
38 success: false,
39 error: 'Password is required',
40 };
41
42 return new Response(JSON.stringify(responseBody), { status: 400 });
43 }
44
45 const hashedPassword = await generateHash(`${password}:${PASSWORD_SALT}`, 'SHA-256');
46
47 if (user!.hashed_password !== hashedPassword) {
48 const responseBody: ResponseBody = {
49 success: false,
50 error: 'Invalid password',
51 };
52
53 return new Response(JSON.stringify(responseBody), { status: 400 });
54 }
55
56 if (disableAll) {
57 user!.extra.multi_factor_auth_methods = [];
58
59 await UserModel.update(user!);
60
61 const responseBody: ResponseBody = {
62 success: true,
63 };
64
65 return new Response(JSON.stringify(responseBody));
66 }
67
68 if (!methodId) {
69 const responseBody: ResponseBody = {
70 success: false,
71 error: 'Method ID is required when not disabling all methods',
72 };
73
74 return new Response(JSON.stringify(responseBody), { status: 400 });
75 }
76
77 const method = getMultiFactorAuthMethodByIdFromUser(user!, methodId);
78

Callers

nothing calls this directly

Calls 6

generateHashFunction · 0.90
cloneMethod · 0.80
disableMethodFromUserMethod · 0.80
updateMethod · 0.45

Tested by

no test coverage detected