title: Unhandled rejection TypeError " converting circular structure to json " when generating json web token
body: <p><a href="https://i.stack.imgur.com/F5Myu.png" rel="nofollow noreferrer">screenshot of error</a>  I am implementing a json web token authentication on an application and i got the error which says:</p>
  
  <p><em>" Unhandled rejection TypeError: converting circular structure to JSON "</em></p>
  
  <p>I further discovered that this error occurs when execution reaches my webtoken generation, because the error didn't occur when i commented it out.</p>
  
  <p>please find my code below:</p>
  
  <pre><code>    const express= require("express");
      const router= express.Router();
      let Users = require("../models/users");
      const jwt= require("jsonwebtoken");
      const configuration = require("../config");
      const app = express();
      app.set("superSecret", configuration.secret);
  
      //registered user submitting signin form
      router.post("/users/signin", function(req, res, next){
        let confirm;
        Users.findOne({
          where:{ username: req.body.username}
        }).then(user =&gt; {
          if(!user){
            res.send("No such users found!")
          }
          else if(user){
             confirmed = user.password === req.body.password;
            if(confirmed){
              let token = jwt.sign(user, app.get("superSecret"), 
                  {expiresIn: 1440}); 
                      //expiresInMinutes
                  res.json({
                              success: true,
                              message: "enjoy your json",
                              token: token
                            })
            }
            else{
              res.send('incorrect password');
            }
          }
        })
      });
  </code></pre>
  
  <p>if i comment out the <em>let token = jwt.sign(user, app.get("superSecret)..</em> there would be no errors. 
  Thanks in anticipation.</p>
  
  <p>find below my Users model.</p>
  
  <pre><code>    const Sequelize= require('sequelize')
      const bcrypt = require('bcrypt-nodejs')
      const sequelStorage = new Sequelize('newtrial', 'olatunji', '5432', {
        host: 'localhost',
        dialect: 'postgres',
  
          pool: {
          max: 5,
          min: 0,
          idle: 10000
        },
  
      });
  
  
      let Users = sequelStorage.define('users', {
        username:{
          type: Sequelize.STRING,
          allowNull: false
        },
        email: {
          type: Sequelize.STRING,
          allowNull: false,
          unique: true,
          validate: { isEmail: true}
        },
        password:{
          type: Sequelize.STRING,
          allowNull:false
        },
        admin:{
          type: Sequelize.BOOLEAN,
          allowNull: false,
          default: false
        }
      })
  
      sequelStorage.sync()
     [enter image description here][1] .catch(function(error){
        console.log(error);
      });
  
      module.exports= Users;
  </code></pre>