keppelen / react-facebook-login

A Component React for Facebook Login
1.19k stars 405 forks source link

How do I redirect to other pages using react router in the "ComponentClicked" function? #253

Open lamngue opened 5 years ago

lamngue commented 5 years ago

I tried:

componentClicked(){ loginWithFaceBook(facebookUser).then(() => { this.props.history.push('/posts'); }); }

but it does not work (loginWithFaceBook and facebookUser) are previously defined.

sutefan1 commented 4 years ago

I'm not sure what you wanna achieve exactly with that code, but as I understood the API you should wait for the response by passing a callback in callback. Once you know the login was successful, you can navigate wherever you desire.

ComponentClicked should merely be used to update UI states or showing a spinner to prevent multiple login attempts at the same time.

Something like this should do the trick:

const authCallback = (response) => {
// store access_token or other information
this.props.history.push('/posts');
}
... other component related stuff
render() { // or return if it's a functional component

<FacebookLogin
        appId={"your app id"}
        onClick={componentClicked}
        callback={authCallback}
      />
}