fix user no pass login and cookie maxAge extension

This commit is contained in:
maleksandrov 2021-04-14 14:56:36 +03:00
parent 05fa05c93d
commit 8d65677fa7
3 changed files with 16 additions and 7 deletions

View File

@ -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
})
}

View File

@ -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) {

View File

@ -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('/')
}