问题
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