JavaScript How to solve Unhandled rejection TypeError: Converting circular structure to JSON for jwt.sign

When I try to create a token for a user like in this 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 => {
                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);
                }
            })

    },
    //
};

I get this error :

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)

controllers/patients.js:27:39 refer to the method jwt.sign on my code

It tells that it's coming from the jwt.sign method

Anyone can tell me what's the matter ?

Answer:1

Currently in React, I am using array.map(function(text,index){}) to iterate through an array. But, how am I going to iterate through two arrays simultaneously using map? EDIT var sentenceList = ...

Currently in React, I am using array.map(function(text,index){}) to iterate through an array. But, how am I going to iterate through two arrays simultaneously using map? EDIT var sentenceList = ...

I want to add dynamic directive inside another directive tempalte. As you see I want to add another directive inside a directive template How do add those dynamic directive there Please help return {...

I want to add dynamic directive inside another directive tempalte. As you see I want to add another directive inside a directive template How do add those dynamic directive there Please help return {...

I have read several tutorials about closures. Some tutorials have some information about execution context. I am confused that execution context and closure seem to the same thing.Does anyone can ...

I have read several tutorials about closures. Some tutorials have some information about execution context. I am confused that execution context and closure seem to the same thing.Does anyone can ...

  1. closure execution context

I have a ScatterChart where I need to draw a diagonal line (of the function y=x) that serves as a visual aid. Is it possible ? if so, how can I do it?

I have a ScatterChart where I need to draw a diagonal line (of the function y=x) that serves as a visual aid. Is it possible ? if so, how can I do it?

  1. draw line google maps
  2. draw line google docs
  3. draw line google earth pro
  4. draw line google maps api
  5. draw line google maps javascript
  6. draw line google maps between two points
  7. draw line google earth
  8. draw line google maps android
  9. draw line google maps coordinates
  10. draw line google sketchup
  11. line draw google chart
  12. draw latitude line google maps
  13. draw straight line google maps
  14. draw line distance google maps
  15. draw dashed line google maps android
  16. draw latitude line google earth
  17. draw a line google
  18. draw straight line google earth
  19. draw a line google maps ios
  20. google maps draw polyline