Trying to set up node and passport using express, and I have stumbled on an issue which I have some problems debugging.
Have a very basic form for signup, and it works all the way up to pressing the sign up button. However, the signup does not work. There is no error message, but the code does recognise that the signup failed (not with an error, but that there is no user). After faffing about a bit, I managed to get as far as that passport.authenticate(signup-local sends a message in info which says "Missing Credentials", but I do not ever know what credentials or why.
The return code I am using on the post is:
app.post('/signup', function(req, res, next) {
passport.authenticate('local-signup', function(err, user, info) {
if (err) {
return next(err); // will generate a 500 error
}
// Generate a JSON response reflecting authentication status
if (! user) {
console.log('Got the following back');
console.log('Error: ' + err);
console.log('User: ' + user);
info = JSON.stringify(info);
console.log('Info: '+ info);
for(var key in info) {
console.log(key);
}
return res.send({ success : false, message : 'authentication failed'});
}
return res.send({ success : true, message : 'authentication succeeded' });
})(req, res, next);
});
And the return is:
GET /signup 304 24.943 ms - -
Got the following back
Error: null
User: false
Info: {"message":"Missing credentials"}
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
POST /signup 200 6.933 ms - 51
I would like to see what the post receives, but not certain how to get that in an easy way:)
OK, so after some fiddling about I figured out what the issue was.
You will need to load the urlencodedParser. So added the following to the beginning of the route
Once that is done, all you have to do is pass the call via urlencodedParser, and Bobs you uncle