• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

hicommonwealth / commonwealth / 12816325622

16 Jan 2025 07:37PM UTC coverage: 47.726% (-0.006%) from 47.732%
12816325622

Pull #10630

github

web-flow
Merge e00f95c9e into 9c820ed0b
Pull Request #10630: Fixed magic api link for updating allowlist

1350 of 3171 branches covered (42.57%)

Branch coverage included in aggregate %.

0 of 3 new or added lines in 1 file covered. (0.0%)

2680 of 5273 relevant lines covered (50.82%)

36.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/libs/model/src/community/UpdateCustomDomain.command.ts
1
import type { Command } from '@hicommonwealth/core';
2
import { AppError, config } from '@hicommonwealth/core';
3
import * as schemas from '@hicommonwealth/schemas';
4
import { models } from '../database';
5
import { isSuperAdmin } from '../middleware';
6

7
/**
8
 * This function will add the custom domain to the database as well as add an entry in heroku.
9
 * @constructor
10
 */
11
export function UpdateCustomDomain(): Command<
12
  typeof schemas.UpdateCustomDomain
13
> {
14
  return {
×
15
    ...schemas.UpdateCustomDomain,
16
    auth: [isSuperAdmin],
17
    body: async ({ payload }) => {
18
      const { community_id, custom_domain } = payload;
×
19

20
      const url = `https://api.heroku.com/apps/${config.HEROKU.HEROKU_APP_NAME}/domains`;
×
21
      const headers = {
×
22
        'Content-Type': 'application/json',
23
        Accept: 'application/vnd.heroku+json; version=3',
24
        Authorization: `Bearer ${config.HEROKU.HEROKU_API_TOKEN}`,
25
      };
26

27
      let response = await fetch(`${url}/${custom_domain}`, {
×
28
        method: 'GET',
29
        headers,
30
      });
31

32
      const domain = await response.json();
×
33

34
      if (domain.id !== 'not_found') {
×
35
        throw new AppError(
×
36
          'Custom Domain is already registered to some community.' +
37
            ' If it is not the correct community, contact engineering',
38
        );
39
      }
40

41
      const magicUrl =
NEW
42
        'https://api.magic.link/v2/api/magic_client/allowlist/add';
×
43

NEW
44
      const magicRequestDomain = await fetch(magicUrl, {
×
45
        method: 'POST',
46
        headers: {
47
          'X-Magic-Secret-Key': config.MAGIC_API_KEY!,
48
          'Content-Type': 'application/json',
49
        },
50
        body: JSON.stringify({
51
          access_type: 'domain',
52
          target_client_id: config.MAGIC_CLIENT_ID!,
53
          value: `https://${custom_domain}`,
54
        }),
55
      });
56

NEW
57
      const magicRequestRedirectUrl = await fetch(magicUrl, {
×
58
        method: 'POST',
59
        headers: {
60
          'X-Magic-Secret-Key': config.MAGIC_API_KEY!,
61
          'Content-Type': 'application/json',
62
        },
63
        body: JSON.stringify({
64
          access_type: 'redirect_url',
65
          target_client_id: config.MAGIC_CLIENT_ID!,
66
          value: `https://${custom_domain}/finishsociallogin`,
67
        }),
68
      });
69

70
      const magicResponseDomain = await magicRequestDomain.json();
×
71
      const magicResponseRedirectUrl = await magicRequestRedirectUrl.json();
×
72

73
      if (
×
74
        magicResponseDomain.status === 'failed' &&
×
75
        magicResponseDomain.error_code != 'ALREADY_WHITELISTED_DOMAIN'
76
      ) {
77
        throw new AppError(magicResponseDomain.message);
×
78
      }
79

80
      if (
×
81
        magicResponseRedirectUrl.status === 'failed' &&
×
82
        magicResponseRedirectUrl.error_code != 'ALREADY_WHITELISTED_DOMAIN'
83
      ) {
84
        throw new AppError(magicResponseRedirectUrl.message);
×
85
      }
86

87
      response = await fetch(url, {
×
88
        method: 'POST',
89
        headers,
90
        body: JSON.stringify({ hostname: custom_domain, sni_endpoint: null }),
91
      });
92

93
      const domainStatus = await response.json();
×
94

95
      if (domainStatus.acm_status === undefined) {
×
96
        throw new AppError(domainStatus.message);
×
97
      }
98

99
      await models.Community.update(
×
100
        {
101
          custom_domain,
102
        },
103
        {
104
          where: {
105
            id: community_id,
106
          },
107
        },
108
      );
109

110
      return domainStatus;
×
111
    },
112
  };
113
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc