title: How to solve Unhandled rejection TypeError: Converting circular structure to JSON for jwt.sign
body: <p>When I try to create a token for a user like in <strong>this code</strong> :</p>
  
  <pre><code>const jwt = require('jsonwebtoken');
  const passport = require('passport');
  const Patient = require('../models').Patient;
  
  module.exports = {
      retrieve(req, res) {
          return Patient
              .find({
                  where: {
                      email: req.body.email,
                  }
              })
              .then(patient =&gt; {
                  if (!patient) return res.json({
                      success: false,
                      msg: 'Patient not found'
                  });
                  const result = Patient.build().verifyPassword(req.body.password, patient.password);
                  if (!result) {
                      return res.json({
                          success: false,
                          msg: 'wrong password'
                      });
                  } else {
                      const token = jwt.sign(patient, secret, {
                          expiresIn: 604800 // 1 week
                      });
                      return res.status(201).send(patient);
                  }
              })
  
      },
      //
  };
  </code></pre>
  
  <p>I get this error :</p>
  
  <blockquote>
    <p>Unhandled rejection TypeError: Converting circular structure to JSON
        at Object.stringify (native)
        at toString (/home/omarou/Documents/Projet/PharmaLiv/node_modules/jws/lib/tostring.js:9:15)
        at jwsSecuredInput (/home/omarou/Documents/Projet/PharmaLiv/node_modules/jws/lib/sign-stream.js:12:34)
        at Object.jwsSign [as sign] (/home/omarou/Documents/Projet/PharmaLiv/node_modules/jws/lib/sign-stream.js:22:22)
        at Object.module.exports [as sign] (/home/omarou/Documents/Projet/PharmaLiv/node_modules/jsonwebtoken/sign.js:146:16)
        at Model.Patient.find.then.patient (/home/omarou/Documents/Projet/PharmaLiv/server/controllers/patients.js:27:39)
        at Model.tryCatcher (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/util.js:16:23)
        at Promise._settlePromiseFromHandler (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/promise.js:512:31)
        at Promise._settlePromise (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/promise.js:569:18)
        at Promise._settlePromise0 (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/promise.js:614:10)
        at Promise._settlePromises (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/promise.js:693:18)
        at Async._drainQueue (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/async.js:133:16)
        at Async._drainQueues (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/async.js:143:10)
        at Immediate.Async.drainQueues (/home/omarou/Documents/Projet/PharmaLiv/node_modules/bluebird/js/release/async.js:17:14)
        at runCallback (timers.js:651:20)
        at tryOnImmediate (timers.js:624:5)</p>
  </blockquote>
  
  <p><code>controllers/patients.js:27:39</code> refer to the method jwt.sign on my code</p>
  
  <p>It tells that it's coming from the jwt.sign method </p>
  
  <p>Anyone can tell me what's the matter ?</p>