How to configure passport facebook using react-redux?

大兔子大兔子 提交于 2020-01-25 08:13:25

问题


I am trying to implement redux with passport facebook strategy. My action works fine i.e, it gets to the backend route and gets the data if I pass a random object. However if in the same route I try to write passport.authenticate('facebook') , it prompts me with the following error in redux:

"Error: Network Error at createError (http://localhost:3000/static/js/0.chunk.js:7219:15) at 
 XMLHttpRequest.handleError (http://localhost:3000/static/js/0.chunk.js:6762:14)"

I have also initialized passport in my server.js file

Server.js file

app.use(passport.initialize());

//passport config
require('./config/passport.js')(passport);

fbAuth.js file (the rotes file)

router.get('/auth/facebook', 
passport.authenticate('facebook')
);

I am not adding the callback function because it never reaches till the first route only.

Finally my fbAuth action in the client side

//LOGIN WITH FACEBOOK
export const fbLogin = () => async dispatch => {
  try{
  dispatch({type: 'LOADING'})
  const res  = await axios.get('/api/auth/facebook')
  dispatch({
   type: 'FB_LOGIN_SUCCESS',
   payload: res
})
}
catch(err){
  dispatch({
    type: 'FB_LOGIN_FAIL',
    payload: err
 })
}

}

In a nutshell what I fail to understand is how to send axios request to backed which could then trigger the passport route.

来源:https://stackoverflow.com/questions/59361530/how-to-configure-passport-facebook-using-react-redux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!