=============== UPDATE ======================
我的网络应用程序适用于localhost,但在部署到Heroku后,singup / login不起作用(不知道需要登录的其他功能)。我正确地连接到mlab(当我在localhost上发布时,我也看到了Heroku URL上的数据)。
我在下面附上了Heroku日志。在我的Chrome控制台上,我得到503(服务不可用)。 my Heroku logs
P.S。刚从编码训练营毕业,对不起,如果我的术语不准确。
谢谢, 阿里克
这是jwt代码:
* Login required middleware
*/
exports.ensureAuthenticated = function(req, res, next) {
if (req.isAuthenticated()) {
next();
} else {
res.status(401).send({ msg: 'Unauthorized' });
}
};
/**
* POST /login
* Sign in with email and password
*/
exports.loginPost = function(req, res, next) {
req.assert('email', 'Email is not valid').isEmail();
req.assert('email', 'Email cannot be blank').notEmpty();
req.assert('password', 'Password cannot be blank').notEmpty();
req.sanitize('email').normalizeEmail({ remove_dots: false });
var errors = req.validationErrors();
if (errors) {
return res.status(400).send(errors);
}
User.findOne({ email: req.body.email }, function(err, user) {
if (!user) {
return res.status(401).send({ msg: 'The email address ' + req.body.email + ' is not associated with any account. ' +
'Double-check your email address and try again.'
});
}
user.comparePassword(req.body.password, function(err, isMatch) {
if (!isMatch) {
return res.status(401).send({ msg: 'Invalid email or password' });
}
res.send({ token: generateToken(user), user: user.toJSON() });
});
});
};
/**
* POST /signup
*/
exports.signupPost = function(req, res, next) {
req.assert('name', 'Name cannot be blank').notEmpty();
req.assert('email', 'Email is not valid').isEmail();
req.assert('email', 'Email cannot be blank').notEmpty();
req.assert('password', 'Password must be at least 4 characters long').len(4);
req.sanitize('email').normalizeEmail({ remove_dots: false });
var errors = req.validationErrors();
if (errors) {
return res.status(400).send(errors);
}
User.findOne({ email: req.body.email }, function(err, user) {
if (user) {
return res.status(400).send({ msg: 'The email address you have entered is already associated with another account.' });
}
user = new User({
name: req.body.name,
email: req.body.email,
password: req.body.password
});
user.save(function(err) {
res.send({ token: generateToken(user), user: user });
});
});
};
答案 0 :(得分:0)
日志抛出此错误:ErrorType:secret必须是字符串或缓冲区。您是否可以提供一些代码,确切地说当您与jsonwebtoken交互时以及设置秘密令牌时?
也许在开发环境中的localhost中,您正确地附加了密码,但在生产中,此变量未正确定义。
否则你得到503,因为服务器崩溃了。