title: Expected "payload" to be a plain object : MEAN
body: <p>This is my code from routes file(users.js)</p>
  
  <pre><code>User.findOne({linkedin_id: req.body.linkedin_id}, function(err, linkedinUser) {
      if(err) {
        console.log('err in finding linkedin user '+err);
      }
      // if user exits
      else if(linkedinUser) {
        console.log('user exist');
        const token = jwt.sign(linkedinUser, config.secret, {expiresIn: 604800});
        res.json({success: true, token: 'JWT '+token, user: {
            id: linkedinUser._id,
            linkedin_id: linkedinUser.linkedin_id,
            name: linkedinUser.name,
            username: linkedinUser.username,
            email: linkedinUser.email,
            lkprofilePic: linkedinUser.profilePic
          }, msg: 'user exits'
        });
      }
      // if user doesn't exist
      else {
        User.create({
          linkedin_id: req.body.linkedin_id,
          name: req.body.name,
          username: req.body.username,
          email: req.body.email,
          lkprofilePic: req.body.lkprofilePic
        }, function(err, result) {
          if(err) {
            res.json({success: false, msg: 'failed to add'})
            console.log('error in adding the data '+err);
          }
          else if(result) {
            const token = jwt.sign(linkedinUser,config.secret,{ expiresIn: 604800 });
            res.json({success: true, token: 'JWT '+token, user: {
              id: result._id,
              linkedin_id: result.linkedin_id,
              name: result.name,
              username: result.username,
              email: result.email,
              lkprofilePic: result.profilePic
            }, msg: 'User added '  });
          }
        });
      }
    });
  </code></pre>
  
  <p>This from the <code>config -&gt; secret</code></p>
  
  <pre><code>module.exports = {
      secret: 'bigfish'
    }
  </code></pre>
  
  <p>This is the error I'm getting in the nodejs console</p>
  
  <blockquote>
    <p>Receiving linkedin data
    D:\product\project-1\node_modules\mongodb\lib\utils.js:132
          throw err;
          ^</p>
    
    <p>Error: Expected "payload" to be a plain object.
        at validate (D:\product\project-1\node_modules\jsonwebtoken\sign.js:34:11)
        at validatePayload (D:\product\project-1\node_modules\jsonwebtoken\sign.js:56:10)
        at Object.module.exports [as sign] (D:\product\project-1\node_modules\jsonwebtoken\sign.js:108:7)
        at D:\product\project-1\routes\users.js:415:29
        at Function. (D:\product\project-1\node_modules\mongoose\lib\model.js:4177:16)
        at parallel (D:\product\project-1\node_modules\mongoose\lib\model.js:2230:12)
        at D:\product\project-1\node_modules\mongoose\node_modules\async\internal\parallel.js:35:9
        at D:\product\project-1\node_modules\mongoose\node_modules\async\internal\once.js:12:16
        at iteratorCallback (D:\product\project-1\node_modules\mongoose\node_modules\async\eachOf.js:52:13)
        at D:\product\project-1\node_modules\mongoose\node_modules\async\internal\onlyOnce.js:12:16
        at D:\product\project-1\node_modules\mongoose\node_modules\async\internal\parallel.js:32:13
        at apply (D:\product\project-1\node_modules\lodash_apply.js:15:25)
        at D:\product\project-1\node_modules\lodash_overRest.js:32:12
        at callbackWrapper (D:\product\project-1\node_modules\mongoose\lib\model.js:2199:11)
        at D:\product\project-1\node_modules\mongoose\lib\model.js:4177:16
        at model.$__save.error (D:\product\project-1\node_modules\mongoose\lib\model.js:359:7)</p>
  </blockquote>
  
  <p>But the data is getting saved in the database &amp; doesn't return the </p>
  
  <pre><code>res.json({success: true, token: 'JWT '+token, user: {
              id: result._id,
              linkedin_id: result.linkedin_id,
              name: result.name,
              username: result.username,
              email: result.email,
              lkprofilePic: result.profilePic
            }, msg: 'User added '  });
  </code></pre>