TypeError:在Object.stringify(native)将循环结构转换为JSON

时间:2016-12-06 04:14:18

标签: javascript json mongoose passport.js

我正在尝试使用护照将我的用户登录到我的应用程序中。尝试序列化用户时出现以下错误。这是说我有一个循环结构,但我不相信我。

是否有人发生这种情况?

{ _id: 584633e911d8450dbccb4628,
  username: 'mloomis',
  email: 'loomis.m@husky.neu.edu',
  password: '$2a$10$wz5M3rURmihkXlG.AQ68QO3h0gYhdvBwa/JTKJuFSS24EnC4/4Rpy',
  __v: 0,
  fitnessGoal: 'Loose Weight',
  heightInches: 5,
  heightFeet: 5,
  weight: 150,
  lastName: 'Loomis',
  firstName: 'Mallory',
  img: 'upload/myFile-1480996068801.jpeg',
  dateCreated: Mon Dec 05 2016 22:43:37 GMT-0500 (Eastern Standard Time),
  messages: [],
  trainers: [],
  favoriteRecipes: [] }
  

TypeError:将循环结构转换为JSON       at Object.stringify(native)       在stringify(C:\ Users \ mloomis \ neu \ webdev \ node_modules \ express \ lib \ response.js:1064:12)       在ServerResponse.json(C:\ Users \ mloomis \ neu \ webdev \ node_modules \ express \ lib \ response.js)   :243:14)       在clientLogin(C:\ Users \ mloomis \ neu \ webdev \ project \ services \ client.service.server.js:10   5:13)       在Layer.handle [as handle_request](C:\ Users \ mloomis \ neu \ webdev \ node_modules \ express \ li   b \路由器\ layer.js:95:5)       在下一个(C:\ Users \ mloomis \ neu \ webdev \ node_modules \ express \ lib \ router \ route.js:131:13)       完成后(C:\ Users \ mloomis \ neu \ webdev \ node_modules \ passport \ lib \ middleware \ authentica   te.js:250:13)       在C:\ Users \ mloomis \ neu \ webdev \ node_modules \ passport \ lib \ middleware \ authenticate.js:257:   15       传递(C:\ Users \ mloomis \ neu \ webdev \ node_modules \ passport \ lib \ authenticator.js:421:14)       在Authenticator.transformAuthInfo(C:\ Users \ mloomis \ neu \ webdev \ node_modules \ passport \ li   b \ authenticator.js:443:5)       在C:\ Users \ mloomis \ neu \ webdev \ node_modules \ passport \ lib \ middleware \ authenticate.js:254:   22       在C:\ Users \ mloomis \ neu \ webdev \ node_modules \ passport \ lib \ http \ request.js:60:7       传递(C:\ Users \ mloomis \ neu \ webdev \ node_modules \ passport \ lib \ authenticator.js:267:43)       在序列化(C:\ Users \ mloomis \ neu \ webdev \ node_modules \ passport \ lib \ authenticator.js:27   6:7)       在serializeClient(C:\ Users \ mloomis \ neu \ webdev \ project \ services \ client.service.server.j)   S:85:9)       传递(C:\ Users \ mloomis \ neu \ webdev \ node_modules \ passport \ lib \ authenticator.js:284:9)

var ClientSchema = new Schema({
    username: String,
    password: String,
    firstName: String,
    lastName: String,
    email: String,
    phone: String,
    weight: Number, 
    heightFeet: Number, 
    heightInches: Number,
    fitnessGoal: {type: String, enum: ['Loose Weight', 'Maintain Weight', 'Gain Weight']},
    img: String,
    favoriteRecipes: [{
        type: mongoose.Schema.ObjectId,
        ref: 'RecipeModel'
    }],
    trainers: [{
        type: mongoose.Schema.ObjectId,
        ref: 'TrainerModel'
    }],
    messages: [{
        message: String,
        trainer: {
            type: mongoose.Schema.ObjectId,
            ref: 'TrainerModel'
        }
    }],
    dateCreated: { type: Date, default: Date.now}
    }, {collection: "client"})

function localStrategy(username, password, done) {
    model
        .clientModel
        .findClientByUsername(username)
        .then(
            function (client) {
                if (client && bcrypt.compareSync(password, client.password)) {
                    if (!client) { 
                        return done(null, false); 
                    }
                    return done(null, client);
                } else {
                    res.send('0');
                }
            },
            function (error) {
                res.sendStatus(400).send(error);
            }
        );
}

function serializeClient(client, done) {
    console.log(client);
    done(null, client);
}

0 个答案:

没有答案