Skip to content

Commit

Permalink
upgrade passport to 0.7.0 and add fix for cookie-session
Browse files Browse the repository at this point in the history
Signed-off-by: Steve Cassidy <steve.cassidy@mq.edu.au>
  • Loading branch information
stevecassidy committed May 20, 2024
1 parent 663391e commit fee26d4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 20 deletions.
34 changes: 18 additions & 16 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"nodemailer": "^6.9.9",
"nyc": "^15.1.0",
"oauth": "0.10.0",
"passport": "0.5.3",
"passport": "^0.7.0",
"passport-google-oauth20": "2.0.0",
"passport-local": "^1.0.0",
"passport-oauth2": "1.7.0",
Expand All @@ -67,7 +67,7 @@
"@types/multer": "^1.4.7",
"@types/node": "20.11.19",
"@types/nodemailer": "^6.4.13",
"@types/passport": "1.0.7",
"@types/passport": "^1.0.16",
"@types/passport-google-oauth20": "2.0.13",
"@types/passport-local": "^1.0.35",
"@types/passport-oauth2": "1.4.15",
Expand Down
19 changes: 19 additions & 0 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,25 @@ app.use(
maxAge: 24 * 60 * 60 * 1000 * 365, // BBS 20220831 changed to 1 year
})
);
// https://github.com/jaredhanson/passport/issues/904
// register regenerate & save after the cookieSession middleware initialization
// fix for bug in passport 0.7.0 and compatibility with cookie-session
app.use((request, response, next) => {
if (request.session && !request.session.regenerate) {
request.session.regenerate = cb => {
if (cb) cb('');
return request.session;
};
}
if (request.session && !request.session.save) {
request.session.save = cb => {
if (cb) cb('');
return request.session;
};
}
next();
});

app.use(express.urlencoded({extended: true}));
// allow large JSON objects to be posted
app.use(express.json({limit: '200mb'}));
Expand Down
8 changes: 6 additions & 2 deletions src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,13 @@ app.get('/', async (req, res) => {
}
});

app.get('/logout/', (req, res) => {
app.get('/logout/', (req, res, next) => {
if (req.user) {
req.logout();
req.logout(err => {

Check warning on line 238 in src/routes.ts

View check run for this annotation

Codecov / codecov/patch

src/routes.ts#L238

Added line #L238 was not covered by tests
if (err) {
return next(err);

Check warning on line 240 in src/routes.ts

View check run for this annotation

Codecov / codecov/patch

src/routes.ts#L240

Added line #L240 was not covered by tests
}
});
}
res.redirect('/');
});
Expand Down

0 comments on commit fee26d4

Please sign in to comment.