TypeError: signin.handleSignin is not a function
Viewed 5 times
I"ve seen this question asked before, but I cannot quite figure out what it is I'm doing wrong. I have an endpoint: app.post('/signin', signin.handleSignin(db, bcrypt)) in my server.js file. The console is alerting me that signin.handleSignIn is not a function. This endpoint is linked to a file in my controllers folder that is signin.js that looks like this:
const handleSignin = (db, bcrypt) => (req, res) => {
const { email, password } = req.body;
if (!email || !password) {
return res.status(400).json('incorrect form submission');
}
db.select('email', 'hash').from('login')
.where('email', '=', email)
.then(data => {
const isValid = bcrypt.compareSync(password, data[0].hash);
if (isValid) {
return db.select('*').from('users')
.where('email', '=', email)
.then(user => {
res.json(user[0])
})
.catch(err => res.status(400).json('unable to get user'))
} else {
res.status(400).json('wrong credentials')
}
})
.catch(err => res.status(400).json('wrong credentials'))
}`enter code here`
export default handleSignin;