2017-05-24 10 views
0

登録ルートにリダイレクトしたくない場合は、2段階のプロセスです(私が現在考えている方法です)。最初のフォーム、ajaxでdbに保存して何かを返し、2番目のフォームを表示してサインアップを完了します。ポストルートは機能しますが、機能は実行されませんパスポートへのAjax呼び出しで認証機能が実行されない

router.route('/register') 
    .post((req, res, next) => { 
     console.log('this bit here works'); 
    passport.authenticate('local-signup', function(error, user) { 
     console.log('it's here that nothing happens'); 
    if(error) { 
     return res.status(500).json(error); 
    } 
     return res.json(user); //this is what I want to return; 
    }) 
}) 

パスポートは1回のポストコールでのみ機能しますか?

+0

構文エラー 'console.log( '何も起こらない');' notice '\' の前に '''。 –

答えて

0

passport.authenticate()はExpressミドルウェアであり、通常の機能ではありません。 the fine manual 1として

「カスタムコールバック」で検索)、それは次のように使用する必要があります(認証が失敗した場合、たとえば、)

router.route('/register').post((req, res, next) => { 
    console.log('this bit here works'); 
    passport.authenticate('local', function(error, user, info) { 
    console.log("it's here that something should happen now."); 
    if (error) { 
     return res.status(500).json(error); 
    } 
    return res.json(user); 
    })(req, res, next); 
}) 

FWIW、userは必ずしも適切なオブジェクトではないかもしれません。

関連する問題