Getting email with mongoose, always undefined

I had the same error and i solve creating a new object from the response of the mongoose query.

exports.getUser = async (req, res) => {
    try {
        const user = await User.findOne({email: email, pass: pass})
        const userParams = {...user}
        const email = userParams._doc.email
        console.log(email)
    } catch(err) {
        console.log(err)
    }
}

I don't recommend you to use this method to auth users, please check auth0 or Oauth2.