【发布时间】:2017-12-18 03:26:07
【问题描述】:
我使用 express 作为后端。我在后端实现了 facebook 身份验证。
router.get('/login/facebook',
passport.authenticate('facebook',{scope:['email']}));
router.get('/login/facebook/callback',
passport.authenticate('facebook',{
successRedirect : '/home',
failureRedirect:'/'
})
);
现在我想通过我的 react 应用调用它,这样当用户登陆主页时,首先他应该通过 facebook 进行身份验证,然后只有他才能看到主页。我该怎么做?
我尝试使用 react-router,但我不明白如何使用 react-router 调用后端。 我还使用 fetch 命令获取了 /login/facebook :
componentDidMount(){
fetch("127.0.0.1:3001/login/facebook");
但它给了我 CORS 错误。
我的 React 应用程序位于 127.0.0.1:3000,快递服务器位于 127.0.0.1:3001。
【问题讨论】: