如何使用快速通行证和Reactjs对用户进行身份验证

时间:2019-05-04 14:37:43

标签: reactjs express passport.js

我已经使用express / mysql / passport创建了一个登录系统,现在我想添加React.js,问题是我将如何在React.js中管理登录?

例如。我有以下路由,使用快速路由在ejs中呈现模板:

module.exports = (app, passport) => {

    app.get('/', function(req, res, next) {
        res.render('index', { title: 'Express' });
    });

    app.post('/login', passport.authenticate('local-login', {
        successRedirect : '/home', // redirect to the secure profile section
        failureRedirect : '/', // redirect back to the signup page if there is an error
        failureFlash : true // allow flash messages
    }),
    function(req, res) {
        if (req.body.remember) {
          req.session.cookie.maxAge = 1000 * 60 * 3;
        } else {
          req.session.cookie.expires = false;
        }
        res.redirect('/');
    });

    app.get('/home', isLoggedIn,  function(req, res, next) {
        res.render('home', { title: 'Express' });
    });

}

function isLoggedIn( req , res , next )  {
    if( req.isAuthenticated() ) {
        return next();
    }
    res.redirect('/');
}

我如何在框架中添加react-router,以及如何使用React + Express对用户进行身份验证?

P.S。我只是要求平时不要要求完全崩溃。

0 个答案:

没有答案
相关问题