A small library for logging in to facebook customized by me, containing some simple functions for some of my small projects.
npm install react-facebook-login-lite
npm install react-facebook-login-lite
`
How to use
`js
import FacebookLogin from 'react-facebook-login-lite';
// or
import { FacebookLogin } from 'react-facebook-login-lite';
const onSuccess = (response) => {
console.log(response);
}
const onFailure = (error) => {
console.log(error);
}
//or typescript
const onSuccess = (response: FacebookLoginAuthResponse) => {
console.log(response);
}
const onFailure = (error: any) => {
console.log(error);
}
ReactDOM.render(
appId="your-facebook-app-id"
onSuccess={onSuccess}
onFailure={onFailure}
/>,
document.getElementById('root')
);
`
Stay Logged in
isSignedIn={true} attribute will call onSuccess callback on load to keep the user signed in.
`jsx
appId="your-facebook-app-id"
onSuccess={onSuccess}
onFailure={onFailure}
isSignedIn={true}
/>
`
onSuccess callback
1. In the onSuccess(response) {...} callback function, You will get a response includes:
* authResponse
* status
* user
2. Send const { accessToken, userID } = response.authResponse to your server
3. Have your server sending a GET request to https://graph.facebook.com/v3.0/${userID}/?fields=id,first_name,last_name,middle_name,email,picture&access_token=${accessToken}`