Closed charnould closed 6 years ago
I'm having this same problem. Is it something with an express version change or something?
I'm relatively sure it's an issue with an express version change. I used this last year with no problems, but running the same project now gives me exact same issue as OP.
Hi!
I can't replicate the issue - can you post a full example? The below is the most minimal version I get together (using the latest Express) and it does work:
const express = require('express');
const app = express();
const passwordless = require('passwordless');
const MemoryStore = require('passwordless-memorystore');
const bodyParser = require('body-parser');
var users = [
{ id: 1, email: 'marc@example.com' },
{ id: 2, email: 'alice@example.com' }
];
passwordless.init(new MemoryStore());
passwordless.addDelivery(
function(tokenToSend, uidToSend, recipient, callback) {
console.log('Hello!\nAccess your account here: http://localhost:3000/'
+ '?token=' + tokenToSend + '&uid='
+ encodeURIComponent(uidToSend));
callback();
});
app.use(bodyParser.urlencoded({ extended: false }));
app.use(passwordless.acceptToken({ successRedirect: '/success'}));
app.get('/', (req, res) => res.send(' \
<html> \
<body> \
<h1>Login</h1> \
<form action="/sendtoken" method="POST"> \
Email: \
<br><input name="user" type="text"> \
<br><input type="submit" value="Login"> \
</form> \
</body> \
</html> \
'));
app.get('/success', (req, res) => res.send('Logged in'));
/* POST login details. */
app.post('/sendtoken',
passwordless.requestToken(
function(user, delivery, callback) {
for (var i = users.length - 1; i >= 0; i--) {
if(users[i].email === user.toLowerCase()) {
return callback(null, users[i].id);
}
}
callback(null, null);
}),
function(req, res) {
res.send('Sent - Check your console!');
});
app.listen(3000, () => console.log('Example app listening on port 3000!'));
I also added a no-config example that allows you to test passwordless in a minimal way: https://github.com/florianheinemann/passwordless/tree/master/examples/console-token
I had the same problem - had no callback()
cast at the end of delivery
If anyone runs into this, make sure you call callback()
at the end of your delivery method!
Hi,
First, thanks for your library. It works almost like a charm! 👍 But I have a small issue and I can't find a way to fix it (I'm a kind of newbie)...
Using your own example (for testing purpose), I've set my
/sendtoken
route, but the request never ends: the email containing the token is sent, the token works... but - using my example - I can'tconsole.log('end here')
or diplaysent
.I tried a few things without any success. It seems to miss a
next()
, but you do not use it on your docs.Do you have an idea what's going on?
Thanks a lot.