Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use backoffice db to verify existence on iam error #262

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}` },
});
Loading