2016-10-03 4 views
0

=============== UPDATE에서 작동 = 가입/로그인 ===================== 로컬 호스트에 있지만 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 }); 
 
    }); 
 
    }); 
 
};

답변

0

로그이 오류가 발생합니다 : ERRORTYPE : 비밀 문자열 또는 버퍼해야

감사합니다, 아리 여기

는 JWT 코드입니다. jsonwebtoken과 상호 작용할 때와 비밀 토큰을 설정할 때 정확하게 코드를 제공 할 수 있습니까?

아마도 개발 환경의 localhost에서 비밀을 올바르게 첨부하고 있지만 프로덕션 환경에서는이 변수가 올바르게 정의되지 않았습니다.

그렇지 않으면 서버가 손상되어 503이됩니다.

+0

덕분에 마테오, 정말 당신의 도움을 주셔서 감사합니다. 나는 코드를 추가했다. 당신이 찾고 있던 코드인가? – erikbrodch

+0

가 해결, 나는 Heroku가에 구성 바르에 토큰 비밀을 추가 할 필요가 있었다. 고마워요 마테오 – erikbrodch

관련 문제