Skip to content

passport authentication always returns missing credentials #2

@NomadXD

Description

@NomadXD

`router.post('/login', auth.optional, (req, res, next) => {
const { body: { user } } = req;
console.log(req.body);
const result = Joi.validate(user, userSchema);

if (result.error) {
	return res.status(422).json({
		errors: result.error
	});
}
console.log('login');
return passport.authenticate('local', { session: false }, (err, passportUser, info) => {
	console.log(err);
	console.log(info);
	if (err) {
		return next(err);
	}

	console.log(passportUser);

	if (passportUser) {
		const user = {
			_id: passportUser.id,
			email: passportUser.email,
			name: passportUser.name,
			surname: passportUser.surname,
			token: generateJWT(passportUser)
		};

		return res.json({ user });
	}

	return res.status(400).send(info);
})(req, res, next);

});`

passport.authenticate always says missing credentials. From the call back err is set to null, user is set to false and info is set to missing credentials. I searched stackoverflow and google but could not find a solution. It always returns missing credentials.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions