2012-12-20 5 views
1

passport-local을 사용할 때 (예제 데이터베이스) 오류에 대한 cutom 페이지로 리디렉션하고 메시지를 표시하는 방법. 여기 코드는 다음과 같습니다 passport-local에서 오류가있는 페이지로 리디렉션하는 방법

app.post('/auth/local', passport.authenticate('local', { 
    successRedirect: '/', 
    failureRedirect: '/', 
    failureFlash: true 
})); 

오류가 발생

이 URL이 더러운 [object Object] 내용으로, /auth/local을 유지 : 같은

passport.use(new LocalStrategy({ 
    passReqToCallback: true 
    }, function(req, username, password, done) { 
    done({error:'mycustomerrormessage'}); 
    } 
)); 

라우팅 보인다.

나는 여권보다 더

done(null, false, { message: "error message"}) 

/로 리디렉션, 나는 메시지를 flash 수 있지만이 경우 리디렉션을 설정하는 방법은 내가 먼저하지 null 매개 변수와 함께 verify 함수를 호출하고 무언가를 호출하는 경우 그 오류는?

답변

0

명시 문서를 기반으로, 당신은 다음과 같은 오류 처리 미들웨어를 구성 할 수 있습니다

app.use(function(err, req, res, next){ 
    console.error(err.stack); 
    res.send(500, 'Something broke!'); 
}); 

네 개의 매개 변수 서명이 오류 처리 정의 있음을 나타냅니다.

http://expressjs.com/guide.html#error-handling

관련 문제