Skip to content
This repository has been archived by the owner on Dec 14, 2023. It is now read-only.

Refactor login/logout to share session clearing code #1489

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ It also contains our legacy front-end. In case of large PR regarding our front-e
If you want to get set up to make a contribution, please see the [cp-local-development repository](https://github.com/CoderDojo/cp-local-development).

General documentation is in the [community-platform repository](https://github.com/CoderDojo/community-platform).

## Debugging

You can see HAPI interactions by setting `HAPI_DEBUG` to `true` in `web/config/development.env`. This then outputs data to `/tmp/hapi-zen-platform.log` inside the zen container.
3 changes: 3 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,9 @@ gulp.task('dev', ['watch-less'], () => {
relativePath('./web/public/components/*'),
relativePath('./web/public/dist/*'),
],
execMap: {
js: "node --max-http-header-size=81920"
},
script: 'index.js',
ext: 'js dust json',
tasks: ['build'],
Expand Down
1 change: 1 addition & 0 deletions web/config/development.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ EVENTS_SERVICE=events2
EMAIL_SERVICE=email
USERS_SERVICE=users
CLUBS_SERVICE=clubs
HAPI_DEBUG=false
HOSTED_URL=http://localhost:8000
RPI_AUTH_URL=http://localhost:9001/
RPI_PROFILE_URL=http://localhost:3002
Expand Down
14 changes: 11 additions & 3 deletions web/controllers/rpi/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ function getErrorRedirectUrl(message = oauthErrorMessage) {
}

function handleRPILogin(request, reply, redirectQueryParams = { login_options: 'v1_signup' }) {
clearSession(request, reply);

const returnTo = request.query['returnTo'];
const state = crypto.randomBytes(20).toString('hex');

Expand All @@ -35,6 +37,8 @@ function handleRPILogin(request, reply, redirectQueryParams = { login_options: '
}

function handleRPILogout(request, reply) {
clearSession(request, reply);

const session = request.state['seneca-login'];
if (!session || (session && !session.token)) {
return reply.redirect('/');
Expand All @@ -43,9 +47,7 @@ function handleRPILogout(request, reply) {
const msg = { role: 'user', cmd: 'logout', token: session.token };
return request.seneca.act(msg, err => {
if (err) return reply(Boom.badImplementation(err));
request.cookieAuth.clear();
clearRpiStateCookie(reply);
delete request.user;

const redirectUri = getLogoutRedirectUri();
return reply.redirect(redirectUri);
});
Expand All @@ -65,6 +67,12 @@ function handleRPIEdit(request, reply) {
reply.redirect(redirectUri);
}

function clearSession(request, reply) {
request.cookieAuth.clear();
clearRpiStateCookie(reply);
delete request.user;
}

function getZenRegisterPayload(decodedIdToken, isAttendee) {
return {
isTrusted: true,
Expand Down