I've been trying to use pg-promise with passportjs, but I can't get to work local-signup. My login works well. Please see below:
passport.use(
"local-signup",
new LocalStrategy(
{
usernameField: "email",
passwordField: "pass",
passReqToCallback: true
},
(req, email, pass, done) => {
process.nextTick(function() {
q.db
.one("select email from users where email = $1", email)
.then(data => {
if (data) {
return done(
null,
false,
req.flash("signupMessage", "User already exists")
);
} else {
console.log("here!?");
q.db
.none(
"insert into users (email, pass)" +
`values (${email}, ${pass})`
)
.then(data => {
console.log("created?");
});
}
})
.catch(err => {
console.log(err);
});
});
}
)
);
The problem here is that, it actually detects if an user is already in the database, but if the user doesn't exists, it doesn't create the username, but instead, skips the whole process.
Any ideas how to fix this issue?
Thank you
nonemethod for putting values to queryonemethod: "When 0 or more than 1 rows are returned, the method rejects"oneOrNone