Skip to content

Commit

Permalink
feat: Use apigateway-http package for responses
Browse files Browse the repository at this point in the history
  • Loading branch information
joostvanderborg committed Nov 8, 2022
1 parent 10b5603 commit 27cde37
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 23 deletions.
20 changes: 5 additions & 15 deletions src/app/auth/handleRequest.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import { Session } from '@gemeentenijmegen/session';
import { OpenIDConnect } from './shared/OpenIDConnect';

function redirectResponse(location: string, code = 302, cookies?: string[]) {
return {
statusCode: code,
body: '',
headers: {
Location: location,
},
cookies: cookies,
};
}
import { Response } from '@gemeentenijmegen/apigateway-http/lib/V2/Response';

export async function handleRequest(cookies: any, queryStringParamCode: string, queryStringParamState: string, dynamoDBClient: any): Promise<any> {
let session = new Session(cookies, dynamoDBClient, { ttlInMinutes: 240 });
await session.init();
if (session.sessionId === false) {
return redirectResponse('/login');
return Response.redirect('/login');
}
const state = session.getValue('state');
const contact_id = session.getValue('contact_id');
Expand All @@ -33,13 +23,13 @@ export async function handleRequest(cookies: any, queryStringParamCode: string,
xsrf_token: { S: OIDC.generateState() },
});
} else {
return { statusCode: 500 };
return Response.error(500);
}
} catch (error: any) {
console.debug('test2', error);
console.error(error.message);
return redirectResponse('/login');
return Response.redirect('/login');
}
const url = contact_id ? `/?contact_id=${contact_id}` : '/';
return redirectResponse(url, 302, [session.getCookie()]);
return Response.redirect(url, 302, [session.getCookie()]);
}
39 changes: 33 additions & 6 deletions src/app/auth/package-lock.json

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

5 changes: 3 additions & 2 deletions src/app/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
"dependencies": {
"@aws-sdk/client-dynamodb": "3.190.0",
"@aws-sdk/client-secrets-manager": "3.190.0",
"@gemeentenijmegen/apigateway-http": "^0.0.2",
"@gemeentenijmegen/session": "^0.0.5",
"cookie": "^0.5.0",
"mustache": "^4.2.0",
"openid-client": "^5.1.10"
},
"devDependencies": {
"aws-sdk-client-mock": "^2.0.0",
"@aws-sdk/types": "3.190.0"
"@aws-sdk/types": "3.190.0",
"aws-sdk-client-mock": "^2.0.0"
}
}

0 comments on commit 27cde37

Please sign in to comment.