Skip to content

Commit

Permalink
feat: disable issuing after callback
Browse files Browse the repository at this point in the history
  • Loading branch information
marnixdessing committed Oct 31, 2022
1 parent 105deb4 commit 87d528e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/app/callback/callbackRequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export async function callbackRequestHandler(params: any, dynamoDBClient: Dynamo
async function handleLoggedinRequest(session: Session, params: any, dynamoDBClient: DynamoDBClient) {

if (session.getValue('issued', 'BOOL')) {
return;
return Response.json({ message: 'Callback already performed' });
}

const bsn = session.getValue('bsn', 'S');
Expand Down
27 changes: 18 additions & 9 deletions src/app/issue/issueRequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,24 @@ export async function issueRequestHandler(cookies: string, brpClient: ApiClient,
* @returns
*/
async function handleLoggedinRequest(session: Session, brpClient: ApiClient, irmaApi: IrmaApi) {
// BRP request
const bsn = session.getValue('bsn');
const brpApi = new BrpApi(brpClient);
const brpData = await brpApi.getBrpData(bsn);
const naam = brpData?.Persoon?.Persoonsgegevens?.Naam ? brpData.Persoon.Persoonsgegevens.Naam : 'Onbekende gebruiker';

let error = undefined;
if (brpData.error) {
error = 'Het ophalen van uw persoonsgegevens is mis gegaan.';

// If issuing already is completed
if (session.getValue('issued', 'BOOL')) {
error = 'Om uw gegevens nog een keer in te laden dient u eerst uit te loggen';
}

// BRP request
let naam = 'Onbekende gebruiker';
let brpData = undefined;
if (!error) {
const bsn = session.getValue('bsn');
const brpApi = new BrpApi(brpClient);
brpData = await brpApi.getBrpData(bsn);
naam = brpData?.Persoon?.Persoonsgegevens?.Naam ?? naam;
if (brpData.error) {
error = 'Het ophalen van uw persoonsgegevens is mis gegaan.';
}
}

// Start IRMA session
Expand Down Expand Up @@ -89,4 +98,4 @@ async function storeIssueEventInSession(brpData: any, session: Session) {
} catch (err) {
console.log('Could not add issue statistics to session', err);
}
}
}
4 changes: 2 additions & 2 deletions test/__snapshots__/main.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 87d528e

Please sign in to comment.