message: Refactored 2fa verification code
diff: @@ -11,8 +11,7 @@ otplib.authenticator.options = {
  window: 1
  }
  -function verify () {
  - return async (req, res, next) => {
  +async function verify (req, res) {
  const { tmpToken, totpToken } = req.body
  try {
  @@ -28,29 +27,26 @@ function verify () {
  const plainUser = utils.queryResultToJson(user)
  - if (isValid) {
  + if (!isValid) {
  + return res.status(401).send()
  + }
  +
  if (utils.notSolved(challenges.twoFactorAuthUnsafeSecretStorage) && user.email === 'J12934@' + config.get('application.domain')) {
  utils.solve(challenges.twoFactorAuthUnsafeSecretStorage)
  }
  - models.Basket.findOrCreate({ where: { userId }, defaults: {} })
  - .then(([basket, created]) => {
  + const [ basket ] = await models.Basket.findOrCreate({ where: { userId }, defaults: {} })
  +
  const token = insecurity.authorize(plainUser)
  plainUser.bid = basket.id // keep track of original basket for challenge solution check
  insecurity.authenticatedUsers.put(token, plainUser)
  +
  res.json({ authentication: { token, bid: basket.id, umail: user.email } })
  - }).catch(error => {
  - next(error)
  - })
  - } else {
  - res.status(401).send()
  - }
  } catch (error) {
  console.error('Failed to verify token identity')
  - console.error(error)
  res.status(401).send()
  }
  }
  -}
  -module.exports.verify = verify
  +
  +module.exports.verify = () => verify
  