我使用express作爲後端。我在後端實施了Facebook身份驗證。如何將Facebook身份驗證添加到我的反應應用程序?
router.get('/login/facebook',
passport.authenticate('facebook',{scope:['email']}));
router.get('/login/facebook/callback',
passport.authenticate('facebook',{
successRedirect : '/home',
failureRedirect:'/'
})
);
現在我想通過我的反應應用程序調用它,以便當用戶登陸主頁時,首先他應該通過Facebook進行身份驗證,然後才能看到主頁。我怎樣才能做到這一點 ?
我試過使用react-router,但我不明白如何使用react-router調用後端。使用fetch命令 我也取/登錄/ Facebook的:
componentDidMount(){
fetch("127.0.0.1:3001/login/facebook");
但它給了我CORS錯誤。
我的反應應用程序是在127.0.0.1:3000和表示服務器在127.0.0.1:3001。