Skip to content

Commit

Permalink
fix: use backoffice db to verify existence on iam error (#262)
Browse files Browse the repository at this point in the history
* fix: use backoffice db to verify existence on iam error

* bump: `v1.4.2`
  • Loading branch information
JeffreyArt1 authored Sep 2, 2024
1 parent 1fda632 commit b1ba6cc
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/sub-cloudrun-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ jobs:
SENTRY_ORG=${{ vars.SENTRY_ORG }},
SENTRY_PROJECT=${{ vars.SENTRY_PROJECT }},
SENTRY_AUTH_TOKEN=${{ secrets.SENTRY_AUTH_TOKEN }},
BACKOFFICE_API_URL=${{ vars.BACKOFFICE_API_URL }},
BACKOFFICE_API_KEY=${{ secrets.BACKOFFICE_API_KEY }},
flags: |
--min-instances=${{ inputs.min_instances }}
--max-instances=${{ inputs.max_instances }}
Expand Down
2 changes: 2 additions & 0 deletions env.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@ namespace NodeJS {
NEXT_PUBLIC_SENTRY_DSN?: string;
SENTRY_ORG?: string;
SENTRY_PROJECT?: string;
BACKOFFICE_API_URL?: string;
BACKOFFICE_API_KEY?: string;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "cuenta-unica-registry",
"description": "Portal de registro de Cuenta Única",
"version": "v1.4.1",
"version": "v1.4.2",
"private": false,
"author": "OGTIC",
"license": "MIT",
Expand Down
34 changes: 31 additions & 3 deletions src/actions/iam.action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,39 @@ export async function findIamCitizen(cedula: string) {
}),
);

const { data: identities } = await backend.listIdentities({
credentialsIdentifier: cedula,
});
const { data: identities } = await backend
.listIdentities({
credentialsIdentifier: cedula,
})
.catch(() => findAccountInBackoffice(cedula));

return {
exists: identities.length !== 0,
};
}

async function findAccountInBackoffice(cedula: string) {
const url = new URL('v1/accounts', process.env.BACKOFFICE_API_URL);
url.searchParams.append('term', cedula);

const resp = await fetch(url, withCredentials());

if (resp.ok) {
return resp
.json()
.then((data: Array<BackofficeAccount>) =>
data.map((data) => ({ ...data, verifiable_addresses: [] })),
)
.then((data) => ({ data }));
}

await resp.json().then(console.error);

return { data: [] };
}

type BackofficeAccount = { id: string; cedula: string };

const withCredentials = () => ({
headers: { 'x-account-apikey': `${process.env.BACKOFFICE_API_KEY}` },
});

0 comments on commit b1ba6cc

Please sign in to comment.