Skip to content

Commit

Permalink
Merge pull request #9402 from hicommonwealth/israel.9372.adding-magic…
Browse files Browse the repository at this point in the history
…-redirect-url

added logic to add redirect url w custom domain
  • Loading branch information
ilijabojanovic authored Oct 3, 2024
2 parents 74b82ae + 7b50933 commit 38cde77
Showing 1 changed file with 32 additions and 6 deletions.
38 changes: 32 additions & 6 deletions libs/model/src/community/UpdateCustomDomain.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function UpdateCustomDomain(): Command<
);
}

const magicRequest = await fetch(
const magicRequestDomain = await fetch(
`https://api.magic.link/v1/api/magic_client/domain/allowlist/add`,
{
method: 'POST',
Expand All @@ -48,18 +48,44 @@ export function UpdateCustomDomain(): Command<
'Content-Type': 'application/json',
},
body: JSON.stringify({
access_type: 'domain',
target_client_id: config.MAGIC_CLIENT_ID!,
domain: `https://${custom_domain}`,
value: `https://${custom_domain}`,
}),
},
);
const magicResponse = await magicRequest.json();

const magicRequestRedirectUrl = await fetch(
`https://api.magic.link/v1/api/magic_client/redirect_url/allowlist/add`,
{
method: 'POST',
headers: {
'X-Magic-Secret-Key': config.MAGIC_API_KEY!,
'Content-Type': 'application/json',
},
body: JSON.stringify({
access_type: 'redirect_url',
target_client_id: config.MAGIC_CLIENT_ID!,
value: `https://${custom_domain}/finishsociallogin`,
}),
},
);

const magicResponseDomain = await magicRequestDomain.json();
const magicResponseRedirectUrl = await magicRequestRedirectUrl.json();

if (
magicResponseDomain.status === 'failed' &&
magicResponseDomain.error_code != 'ALREADY_WHITELISTED_DOMAIN'
) {
throw new AppError(magicResponseDomain);
}

if (
magicResponse.status === 'failed' &&
magicResponse.error_code != 'ALREADY_WHITELISTED_DOMAIN'
magicResponseRedirectUrl.status === 'failed' &&
magicResponseRedirectUrl.error_code != 'ALREADY_WHITELISTED_DOMAIN'
) {
throw new AppError(magicResponse.message);
throw new AppError(magicResponseRedirectUrl);
}

response = await fetch(url, {
Expand Down

0 comments on commit 38cde77

Please sign in to comment.