1.4.0 • Published 6 years ago

react-facebook-auth v1.4.0

Weekly downloads
780
License
MIT
Repository
github
Last release
6 years ago

React Facebook Authentication

Build Status redux-modal-container codecov

Allows developers to receive a facebook authentication token that can be used by a backend service.

Installation

To install the latest version:

npm install --save react-facebook-auth

or

yarn add react-facebook-auth

How to use

import React from 'react';
import ReactDOM from 'react-dom';
import FacebookAuth from 'react-facebook-auth';

const MyFacebookButton = ({ onClick }) => (
  <button onClick={onClick}>
    Login with facebook
  </button>
);

const authenticate = (response) => {
  console.log(response);
  // Api call to server so we can validate the token
};

const App = () => (
  <div>
    <h1>Facebook Auth</h1>
    <FacebookAuth
      appId="<app-id>"
      callback={authenticate}
      component={MyFacebookButton}
    />
  </div>
);

ReactDOM.render(
  <App />,
  document.getElementById('root'),
);

A full example can be found in examples directory.

Available Props

ParamsTypeInfo
appIdstringFacebook application id. Check https://developers.facebook.com
scopestringComma separated list of extended permissions
fieldsstringname,email,picture
callbackfunctionCallback triggered when we receive a response from facebook.
onFailurefunctionIf provided, will be triggered on failed requests.
returnScopesbooleanWhen true, the granted scopes will be returned in a comma-separated list in the grantedScopes field of the authResponse
autoLoadbooleanDefaults to: false
xfbmlbooleanDefaults to: false
cookiebooleanDefaults to: false
reAuthenticatebooleanAsks the person to re-authenticate unconditionally. Defaults to: false
reRequestbooleanAsks the person again for revoked permissions. Defaults to: false
redirectUristringDefaults to: '/'
versionstringFacebook SDK version. Defaults to: 2.8
languagestringDefaults to: en_US
disableRedirectbooleanDefaults to: false
customPropsobjectAllows custom props passing to the custom element.
componentnodeCustom react element that returns a button element.

License

MIT