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

Function post

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

Source from the content-addressed store, hash-verified

17}
18
19async function post({ user }: RequestHandlerParams) {
20 const isMultiFactorAuthEnabled = await AppConfig.isMultiFactorAuthEnabled();
21
22 if (!isMultiFactorAuthEnabled) {
23 const responseBody: ResponseBody = {
24 success: false,
25 error: 'Multi-factor authentication is not enabled on this server',
26 };
27
28 return new Response(JSON.stringify(responseBody), { status: 403 });
29 }
30
31 const config = await AppConfig.getConfig();
32 const issuer = new URL(config.auth.baseUrl).hostname;
33 const methodId = MultiFactorAuthModel.generateMethodId();
34 const setup = await TOTPModel.createMethod(methodId, 'Authenticator App', issuer, user!.email);
35
36 if (!user!.extra.multi_factor_auth_methods) {
37 user!.extra.multi_factor_auth_methods = [];
38 }
39
40 user!.extra.multi_factor_auth_methods.push(setup.method);
41
42 await UserModel.update(user!);
43
44 const responseData: ResponseBody = {
45 success: true,
46 data: {
47 methodId: setup.method.id,
48 secret: setup.plainTextSecret,
49 qrCodeUrl: setup.qrCodeUrl,
50 backupCodes: setup.plainTextBackupCodes,
51 },
52 };
53
54 return new Response(JSON.stringify(responseData));
55}
56
57export default page({
58 post,

Callers

nothing calls this directly

Calls 5

getConfigMethod · 0.80
generateMethodIdMethod · 0.80
createMethodMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected