findOne returning me null even though there is entries in my DB NodeJS

84 Views Asked by At

This is my User Model

    module.exports = (sequelize, DataTypes) => {
    const User = sequelize.define("User", {
        email: {
            type: DataTypes.STRING,
            allowNull: false,
            unique: true
        },
        password: {
            type: DataTypes.STRING,
            allowNull: false
        }
    })
    return User
}

and i am try to find if there is any entry in my User table of given email

app.post("/login", (req, res) => {
    let email = req.body.email
    User.findOne({ where: { email: email } }).then((result) => {
        if (result == null) {
            console.log("data is null", result)
            res.send("No data found")
        } else {
            res.send(result)
        }
    }).catch((err) => {
        console.log(err, "Error in find one")
    })
})

this is the the output in my terminal

Executing (default): SELECT `id`, `email`, `password`, `createdAt`, `updatedAt` FROM `Users` AS `User` WHERE `User`.`email` = '[email protected]';
data is null null

This is the User table in my DB .This is my User table in DB

0

There are 0 best solutions below