0
===============更新===================== =註冊/登錄可在Localhost上使用,但不能在Heroku上使用
我需要將令牌密碼添加到Heroku上的配置變量。
我的web-app在localhost上工作,但部署到Heroku singup/login後無效(不知道其他功能,需要登錄)。我已正確連接到mlab(當我在本地主機上發佈時,我也看到了有關Heroku URL的數據)。
我在下面附加了Heroku日誌。在我的Chrome控制檯上,我得到503(服務不可用)。 my Heroku logs
P.S.剛剛從編碼訓練營畢業,對不起,如果我的術語不準確。
感謝, 阿里克
這裏是智威湯遜代碼:
* 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 });
});
});
};
感謝Mateo,非常感謝您的幫助。我添加了代碼,這是你在找什麼? – erikbrodch
解決了,我需要將令牌密碼添加到Heroku上的配置變量。感謝Mateo – erikbrodch