florianheinemann / passwordless

node.js/express module to authenticate users without password
MIT License
1.95k stars 129 forks source link

logged_in verification link works always the second time and not the first #134

Closed ghost closed 3 years ago

ghost commented 3 years ago

So my issue, is when I click the link sent to the email I can only log in after a second attempt. I don't know why? what could be the problem ? cache ? thanks a lot

ghost commented 3 years ago

these are routes:

router.get('/login', function (req, res) {
  res.render('login');
});

router.post(
  "/sendtoken",
  // urlencodedParser,
  global.passwordless.requestToken(
    // Simply accept every user*
    function (user, delivery, callback) {
      console.log(user)
      callback(null, user);
    }
  ),
  function (req, res) {
    console.log(req.user)
        res.send('Check your email. You will be able to login from there.');
  }
);

router.get('/logged_in', global.passwordless.acceptToken(), 
    function(req, res) {
    req.session.user = req.user;
        res.render('messages', { title: 'Express', message: 'User login', success: "User has been successfully logged in :)" });
});

Also when I post send the email it does not redirect or send this message as expected:

res.send('Check your email. You will be able to login from there.');