From 8d65677fa793894125cded043a5cd751f8d5dca8 Mon Sep 17 00:00:00 2001 From: maleksandrov Date: Wed, 14 Apr 2021 14:56:36 +0300 Subject: [PATCH] fix user no pass login and cookie maxAge extension --- middleware/auth.js | 3 ++- routes/index.js | 19 ++++++++++++++----- src/store/app/actions.js | 1 - 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/middleware/auth.js b/middleware/auth.js index f5d1a51..a466388 100644 --- a/middleware/auth.js +++ b/middleware/auth.js @@ -12,8 +12,9 @@ module.exports = { if (user && !req.originalUrl.match(/\/logout/)) { // Extend the tokens life while the user is browsing const token = user.generateJWT() + const domain = req.hostname === 'localhost' ? 'localhost' : `.${req.hostname.split('.').slice(-2).join('.')}` // Set cookie on top level domain for auth proxying res.cookie('jwt', token, { - domain: `.${req.host.split('.').slice(-2).join('.')}`, // Set cookie on top level domain for auth proxying + domain: domain, maxAge: 3600000 }) } diff --git a/routes/index.js b/routes/index.js index fb72c52..9444387 100644 --- a/routes/index.js +++ b/routes/index.js @@ -28,17 +28,26 @@ router.post( }) } + if (req.body.username === undefined) { + return res.status(403).json({ + status: 'error', + result: 'No username provided!' + }) + } + const user = await User.findOne({ where: { username: req.body.username } }) - if (!user || !user.verifyPassword(req.body.password)) { - return res.status(403).json({ - status: 'error', - result: 'invalid_user' - }) + if (req.body.username && req.body.password) { + if (!user || !user.verifyPassword(req.body.password)) { + return res.status(403).json({ + status: 'error', + result: 'invalid_user' + }) + } } if (user.multifactorEnabled && !req.body.totp) { diff --git a/src/store/app/actions.js b/src/store/app/actions.js index fc91074..7b3191f 100644 --- a/src/store/app/actions.js +++ b/src/store/app/actions.js @@ -218,5 +218,4 @@ export async function logout(context) { // console.log(data) await axios.get(process.env.BACKEND_LOCATION + 'logout') context.commit('logout') - this.$router.push('/') }