diff --git a/server/package-lock.json b/server/package-lock.json index 42c6f94d..943a1e2f 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -30,7 +30,7 @@ "nodemailer": "^6.9.15", "ogr2ogr": "^3.1.1", "parse-css-color": "^0.2.1", - "passport": "^0.5.3", + "passport": "^0.7.0", "passport-azure-ad": "^4.3.5", "passport-google-oauth20": "^2.0.0", "pdfmake": "^0.2.12", @@ -8956,12 +8956,13 @@ } }, "node_modules/passport": { - "version": "0.5.3", - "resolved": "https://registry.npmjs.org/passport/-/passport-0.5.3.tgz", - "integrity": "sha512-gGc+70h4gGdBWNsR3FuV3byLDY6KBTJAIExGFXTpQaYfbbcHCBlRRKx7RBQSpqEqc5Hh2qVzRs7ssvSfOpkUEA==", + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/passport/-/passport-0.7.0.tgz", + "integrity": "sha512-cPLl+qZpSc+ireUvt+IzqbED1cHHkDoVYMo30jbJIdOOjQ1MQYZBPiNvmi8UM6lJuOpTPXJGZQk0DtC4y61MYQ==", "dependencies": { "passport-strategy": "1.x.x", - "pause": "0.0.1" + "pause": "0.0.1", + "utils-merge": "^1.0.1" }, "engines": { "node": ">= 0.4.0" diff --git a/server/package.json b/server/package.json index 940ebdc1..6c60fea4 100644 --- a/server/package.json +++ b/server/package.json @@ -59,7 +59,7 @@ "nodemailer": "^6.9.15", "ogr2ogr": "^3.1.1", "parse-css-color": "^0.2.1", - "passport": "^0.5.3", + "passport": "^0.7.0", "passport-azure-ad": "^4.3.5", "passport-google-oauth20": "^2.0.0", "pdfmake": "^0.2.12", diff --git a/server/src/auth/index.ts b/server/src/auth/index.ts index a2d1c41c..7e737272 100644 --- a/server/src/auth/index.ts +++ b/server/src/auth/index.ts @@ -47,14 +47,14 @@ export function configureAuth(app: Express) { // Logout route app.get('/logout', (req, res) => { - req.session.destroy((error) => { - req.logOut((err) => { - if (err) { - return req.next(err); - } - res.redirect('/'); + res.clearCookie('connect.sid'); + req.logout((err) => { + if (err) { + return req.next(err); + } + req.session.destroy((err) => { + res.redirect(process.env.AUTH_LOGOUT_URL); }); - res.redirect(process.env.AUTH_LOGOUT_URL); }); }); @@ -112,6 +112,7 @@ export function ensureAuthenticated(options?: { redirectToLogin?: boolean }) { ) { return next(); } + const fail = () => { if (options?.redirectToLogin) { // Provide original request URL for redirection after authentication. @@ -122,14 +123,19 @@ export function ensureAuthenticated(options?: { redirectToLogin?: boolean }) { res.status(401).send('Unauthorized'); } }; - req.session?.destroy(() => { - req.logOut((err) => { + + if (req.session) { + res.clearCookie('connect.sid'); + req.logout((err) => { if (err) { return req.next(err); } - res.redirect('/'); + req.session.destroy((err) => { + fail(); + }); }); + } else { fail(); - }) ?? fail(); + } }; }