1.0.0 • Published 3 years ago

react-facebook-login-lite v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

React Facebook Login Lite

React Facebook Login / Log-in Component for React

Install

npm install react-facebook-login-lite

How to use

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(
    <FacebookLogin 
      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.

    <FacebookLogin 
      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
  1. Send const { accessToken, userID } = response.authResponse to your server
  2. 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}

More details can be found in the official Facebook for devolopers:

Login Props

paramsvaluedefault valuedescription
appIdstringREQUIREDYou can create a appId by creating a facebook app
scopestringpublic_profile,email
languagestringen_US
versionstringv10.0
fieldsstringid,email,first_name,last_name,middle_name,name,picture,short_name
heightstring50px
themestringlightThere are two values: 'dark' and 'light'
imgSrcstringfacebook
btnTextstringSign in with Facebook
onSuccessfunctionREQUIRED
onFailurefunctionREQUIRED
isSignedInbooleanfalseIf true will auto login your facebook

onFailure callback

onFailure callback is called when either initialization or a signin attempt fails.

property namevaluedefinition
erroranyError code

More details can be found in the official Facebook docs:

👉 Follow me on Youtube: @devat-vietnam

👉 Buy Me a Coffee . Thank You ! 💗: (https://www.buymeacoffee.com/QK1DkYS)