简体   繁体   中英

my node app is working fine on localhost but when i deployed on heroku , it is giving me application error. you can read description below

i have a node app with express backend and i am using ejs on front-end. my app has authentication and login and signup pages as well.

my node app is working fine on localhost but when i deployed on heroku, it is giving me application error --

Application error An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command heroku logs --tail

when I run heroku logs --tail on my vs code terminal it shows me -

**2021-05-16T04:15:48.851524+00:00 app[web.1]: TypeError: Cannot read property 'password' of null 2021-05-16T04:15:48.851525+00:00 app[web.1]: at /app/routes/authRoutes.js:37:17

here is my authRoutes code -

// login for existing user
router.post('/login',async(req,res)=>{

    await User.findOne({email:req.body.email},(err,user)=>{

        // verfying email id
        if(err) return res.send({msg:"email id does not exists"})

        //verfying password
        if(user.password!=req.body.password) return res.send({msg:"password is wrong"})
        else return res.send({_id:user._id,msg:"verified"});
    })
})

my app is deployed on the link - https://facechatapp.herokuapp.com/ you can go and have a look.

even when i run my app first time, it runs without error but when i tried to use my app on my phone's chrome browser,after that, it shows this message as a webpage-

An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details. You can do this from the Heroku CLI with the command heroku logs --tail

please let me know if you need more information. i know there are other similar questions but as a newbie, i am unable to figure out my problem thanks in advance

There could be 2 mistakes that I think could be.. however, I am quite confident that this error is because of possible mistake number 2

Possible Mistake number 1

In your User Model you have set your password field select:false and the password field looks something like this

    password: {
      type: String,
      require: [true, "Please provide a Password"],
      minlength: 6,
      select: false,
    },

if this is the case then your User.findone() is missing one key option that is .select('password')

your query should look something like this

    User.findOne({email:req.body.email})
        .select('password')
        .then((usr)=>{
            //... Do you Stuff Here
        }).catch((err)=> {
           return res.send({msg:"password is wrong"})
        })

Possible Mistake number 2

You are not sending email with the correct key:value pair in your request i suggest you double check if your ajax/axios, I only say this because as per the error it tried to find a password field on null which only means that it was unable to find a user with that email. which in this case could be malformed.. or not there at all due to wronge key:val pair..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM