【问题标题】:Node & MongoDB - TypeError: Cannot set property 'userProfileModel' of undefined节点和 MongoDB - TypeError:无法设置未定义的属性“userProfileModel”
【发布时间】:2017-03-03 17:38:13
【问题描述】:

我在尝试在 Postman 中进行登录测试时遇到此错误。我已经进行了注册测试,所有输入字段都注册了 200 状态,并确保所有条目都使用 Robomongo 发布。但是当我尝试使用userNamepassword 登录时,我会收到以下类型错误:

(node:13962) DeprecationWarning: crypto.pbkdf2 without specifying a digest is deprecated. Please specify a digest
/Users/Wilo/Desktop/myway_stuff/myway_app/MyWay/server/controllers/account.js:63
                    me.account.userProfileModel = userProfileModel;
                                                ^

TypeError: Cannot set property 'userProfileModel' of undefined
    at InternalFieldObject.ondone (/Users/Wilo/Desktop/myway_stuff/myway_app/MyWay/server/controllers/account.js:63:49)

这是一个 sn-p,其中登录功能在我的 account.js 控制器中执行:

AccountController.prototype.logon = 函数(用户名、密码、回调){

var me = this;

me.userModel.findOne({ userName: userName }, function (err, user) {

    if (err) {
        return callback(err, new me.ApiResponse({ success: false, extras: { msg: me.ApiMessages.DB_ERROR } }));
    }

    if (user && user.passwordSalt) {

        me.hashPassword(password, user.passwordSalt, function (err, passwordHash) {

            if (passwordHash == user.passwordHash) {

                var userProfileModel = new me.UserProfile({
                    userName: user.userName,
                    email: user.email,
                    firstName: user.firstName,
                    lastName: user.lastName
                });

                //Save to HTTP account
                me.account.userProfileModel = userProfileModel; // This is Line 63 in the stacktrace
                me.account.id = me.uuid.v4();

                //Save to persistent account
                me.userAccount.userId = user._id;
                me.userAccount.accountId = me.account.id;

                me.userAccount.save(function (err, accountData, numberAffected) {

                    if (err) {
                        return callback(err, new me.ApiResponse({ success: false, extras: { msg: me.ApiMessages.DB_ERROR } }));
                    }

                    if (numberAffected === 1) {
                        // Return the user profile so the router sends it to the client app doing the logon.
                        return callback(err, new me.ApiResponse({
                            success: true, extras: {
                                userProfileModel: userProfileModel,
                                accountId: me.account.id
                            }
                        }));                            
                    } else {

                        return callback(err, new me.ApiResponse({ success: false, extras: { msg: me.ApiMessages.COULD_NOT_CREATE_ACCOUNT } }));
                    }
                });                    
            } else {
                return callback(err, new me.ApiResponse({ success: false, extras: { msg: me.ApiMessages.INVALID_PWD } }));
            }
        });
    } else {
        return callback(err, new me.ApiResponse({ success: false, extras: { msg: me.ApiMessages.EMAIL_NOT_FOUND } }));
    }

});

};

非常感谢有关此问题的任何帮助。

【问题讨论】:

    标签: javascript node.js mongodb mongoose


    【解决方案1】:

    看起来你的“我”变量没有帐户变量/参数。

    【讨论】:

      猜你喜欢
      • 2020-08-10
      • 1970-01-01
      • 2020-07-15
      • 2015-09-09
      • 2021-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多