Git Product home page Git Product logo

react-facebook-login's Introduction

React Facebook Login

NPM version NPM downloads NPM bundle size CI CD GitHub Stars


React Component for Facebook Login. aims to improve react-facebook-login.
한글 가이드

  • 💙 Typescript support
  • 📦 6kb mini library
  • 👫 All browsers supported
  • 🏃 Currently maintaining

Table of contents

Getting Started

npm i --save @greatsumini/react-facebook-login
# or
yarn add @greatsumini/react-facebook-login

Usage

Component

import FacebookLogin from '@greatsumini/react-facebook-login';

// default
<FacebookLogin
  appId="1088597931155576"
  onSuccess={(response) => {
    console.log('Login Success!', response);
  }}
  onFail={(error) => {
    console.log('Login Failed!', error);
  }}
  onProfileSuccess={(response) => {
    console.log('Get Profile Success!', response);
  }}
/>

// custom style
<FacebookLogin
  appId="1088597931155576"
  style={{
    backgroundColor: '#4267b2',
    color: '#fff',
    fontSize: '16px',
    padding: '12px 24px',
    border: 'none',
    borderRadius: '4px',
  }}
/>

// custom render function
<FacebookLogin
  appId="1088597931155576"
  onSuccess={(response) => {
    console.log('Login Success!', response);
  }}
  onFail={(error) => {
    console.log('Login Failed!', error);
  }}
  onProfileSuccess={(response) => {
    console.log('Get Profile Success!', response);
  }}
  render={({ onClick, logout }) => (
    <CustomComponent onClick={onClick} onLogoutClick={logout} />
  )}
/>

// custom params, options
<FacebookLogin
  appId="1088597931155576"
  useRedirect
  initParams={{
    version: 'v10.0',
    xfbml: true,
  }}
  dialogParams={{
    response_type: 'token',
  }}
  loginOptions={{
    return_scopes: true,
  }}
/>

FacebookLoginClient

You can manually call facebook sdk related functions with FacebookLoginClient

import { FacebookLoginClient } from '@greatsumini/react-facebook-login';

FacebookLoginClient.getLoginStatus((res) => {
  console.log(res.status);
});

FacebookLoginClient.login((res) => {
  console.log(res);
});

FacebookLoginClient.getProfile((res) => {
  console.log(res.id, res.name, res.email);
});

FacebookLoginClient.logout(() => {
  console.log('logout completed!');
});

Examples

You can checkout examples here

Props

Check all available params,options here

Property Description Type Default
appId * Your application ID. string -
language API version string 'en_US'
scope Comma seperated list of permissions for login. string 'public_profile, email'
fields fields return by /me (profile) string 'name,email,picture'
onSuccess function -
onFail function -
onProfileSuccess function -
style css properties for login button CSSProperties -
children Children Component ReactNode | ReactNodeArray "Login with Facebook"
render Callback which render custom component function -
autoLoad if true, request login on mount boolean false
useRedirect if true, use redirect instead of window.FB.login boolean false (forced to be true in fb browers (ref))
useCustomChat if true, append 'xfbml.customerchat' to sdk url boolean false
initParams params for FB.init InitParams docs
dialogParams params for login dialog DialogParams docs
loginOptions options for FB.login LoginOptions docs

Stay in touch

License

React Facebook Login is MIT licensed.

Links

react-facebook-login's People

Contributors

caseyleeyy avatar emish89 avatar greatsumini avatar gugu avatar hamaad-siddiqui avatar harrywebdev avatar mrbartusek avatar polmrt avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-facebook-login's Issues

How's the mobile support and the suggestion

At first glance, the source code is based on keppelen/react-facebook-login. And there is a big unsolved issue on Mobile, especially newer iOS safari.

The more interesting is that you remove the isMobile and disableMobileRedirect in this package.

That comes the question, how did you slove It?

I think this is the most interesting thing that encourage others to use this package, and you might want to add in Readme 😄

By the way, I didn't use official version, because the bad typescript support, I need to use the fork version to get render. Hope this package could replace successfully 👍

Status Cancelled on Production

When on development it is authenticating well but on production it returned status of cancelled I do not know what may be the issue. May you please help

click on "x" button (closing pop-up window) not handled.

if I close login window by pressing on 'x' button, nothing returns. And there's no other way to cancel login process, at first click(before you enter your password).
For example if I set a loading modal, on click on 'x' button and try to cancel the login process, pop-up window is closed, but I don't receive any callback about login closed, e.g "Login canceled" or something like this.

Latest release v2.1.4 doesn't include any "dist"

@greatSumini I ran the following:

$ yarn add @greatsumini/[email protected]
$ ls node_modules/@greatsumini/react-facebook-login 
CHANGELOG.md  dist  LICENSE  package.json  README.md  renovate.json

And then updated to the latest v2.1.4

$ yarn add @greatsumini/[email protected]
$ ls node_modules/@greatsumini/react-facebook-login
LICENSE  package.json  README.md  renovate.json

And no dist is included.

When importing the component like

import FacebookLogin from '@greatsumini/react-facebook-login';

There is an error

./src/login.js
Cannot find module: '@greatsumini/react-facebook-login'. Make sure this package is installed.

You can install this package by running: yarn add @greatsumini/react-facebook-login.

Is there a way to call the Graph API from this library after successful login?

Hello! First of all, thanks for maintaining a library that does this work of handling login for us. Facebook docs on this are really a hassle, especially with newer technologies such as React, integration is not as seamless.

Now for my question, I was wondering if there is a way inside this library to make get requests to the Graph API. Or should I go straight to the Facebook docs looking for a method that does this?

Sorry if this looks kind of a dumb question. Thanks in advance! :)

upgrade docs

add detail usages for each props

  • use storybook

add prop for Facebook Customer Chat Plugin

add useCustomerChat prop (it append 'xfbml.customerchat' to sdk url)

--- original content ---

I am using this package to enable Facebook login. And using GTM to load Facebook Customer Chat Plugin on my website. However, adding the plugin makes the auth fail with FB.login called before FB.init error - assuming it's because loading the SDK again is override the previous load?

What's the correct way to handle this?

Could I create a PR to modify the base url here to be configurable from the props to be the extended url sdk/xfbml.customerchat.js instead, similar to locale?

How to get auth code

Hello Sumin. Nice work on rewriting codebase to typescript. How does one get only authorization code with profile info

api version v13.0

It would be nice if you update the for the api version option for initparams

CSRF prevention when using redirect method

Hi there, thanks for making this library!

I have decided to implement the sign in flow for my application using the redirect method - I'm wondering what the preferred way of setting and verifying CSRF state in this case is, and how it can be done with this library. What I want to do is have it first redirect to a server side URL that I control (where I can set a CSRF state cookie), and then redirect to the Facebook login flow. It looks like if I do this, then I might not be able to use this library - is there some way that support could be added for this kind of "pre-redirect"?

If you're receptive to the idea, I could suggest something and submit a PR.

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

github-actions
.github/workflows/ci.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
.github/workflows/npm-publish.yml
  • actions/checkout v3
  • actions/setup-node v3
  • actions/cache v3
npm
package.json
  • @babel/core 7.24.4
  • @mdx-js/react 3.0.1
  • @testing-library/jest-dom 6.4.2
  • @testing-library/react 14.3.1
  • @types/jest 29.5.12
  • @types/node 20.12.7
  • @types/react 18.3.1
  • @types/testing-library__jest-dom 5.14.9
  • @typescript-eslint/eslint-plugin 5.62.0
  • @typescript-eslint/parser 5.62.0
  • babel-loader 9.1.3
  • eslint 8.57.0
  • eslint-config-prettier 9.1.0
  • eslint-plugin-import 2.29.1
  • jest 29.7.0
  • jest-environment-jsdom 29.7.0
  • npm-run-all2 6.1.2
  • prettier 3.2.5
  • react 18.3.1
  • react-dom 18.3.1
  • rimraf 5.0.5
  • ts-jest 29.1.2
  • typescript 5.4.5
  • react ^16.0.0 || ^17.0.0 || ^18.0.0

  • Check this box to trigger a request for Renovate to run again on this repository

How to logout once we are logged in?

I just saw that you are improving the original react-facebook-login by keppelen. However, do you know how to implement logout in this case? I do not found any solution on it

No documentation

The documentation used to be in the README but it looks like it was replaced by the storybook which is not working at the moment.

Please update documentation

Hi,

it looks like your documentation is outdated. I follow your example for client and without setting correct version in init method i end up with FB error "init is not called with valid version."
When i use valid version and click on login i end up in error facebook page "Sorry, something went wrong." but i cant identify what is the problem.

Type error for graph api v18.0

/** Determines which versions of the Graph API and any API dialogs or plugins are invoked
*
* (available versions: https://developers.facebook.com/docs/graph-api/changelog)
* @default 'v9.0' */
version?:
| 'v7.0'
| 'v8.0'
| 'v9.0'
| 'v10.0'
| 'v11.0'
| 'v12.0'
| 'v13.0'
| 'v14.0'
| 'v15.0'
| 'v16.0'
| 'v17.0';

facebookNotLoaded error on button click

I am getting the error facebookNotLoaded. Do I need to load some sdk for this to work?

this is what I have:

import React from "react";
import FacebookLogin from "@greatsumini/react-facebook-login";

const responseFacebook = (response) => {
  console.log(response);
};

export default function FacebookLoginComp({ data, title }) {
  return (
    <FacebookLogin
      appId="{APP_ID}"
      initParams={{
        version: "v14.0",
        xfbml: true,
      }}
      scope="public_profile,instagram_basic,instagram_manage_insights,pages_read_engagement,pages_show_list"
      onFail={(e) => console.log("error", e)}
      onSuccess={responseFacebook}
      onProfileSuccess={responseFacebook}
    />
  );
}

Facebook Login Popup auto opens for any path containing qurey param "code"

from keppelen/react-facebook-login#327

--- original content ---
Hi, first of all thanks for this amazing library. I have encountered an issue while integrating this library with other login methods also present. Everything works fine until I get redirected from apples authentication with a query parameter code and the facebook popup would automatically open up.

I am not sure what the behavior should be, but in this case it's not creating an issue for me where I just want the app to continue with apple's login.

I think the condition can be corrected here in this function maybe but I am not sure.

// src/facebook.js
isRedirectedFromFb() {   
      const params = window.location.search;    
      return (      decodeParamForKey(params, 'state') === 'facebookdirect' && (decodeParamForKey(params, 'code') ||  
      decodeParamForKey(params, 'granted_scopes'))    );  
}
```

Why does it not return an authenticated state after successful log in?

After successfully logging in, the callback for onSuccess is not called.

When you click the login with facebook button again, it now calls the onSuccess callback.

Basically you need to click the login button 2 times to show that you're authenticated


I'm developing in localhost:3000 with HTTPS=true set in package.json

import React, { useEffect } from 'react';
import { ButtonProps } from '@mantine/core';
import FacebookLogin from '@greatsumini/react-facebook-login';

export function FacebookButton(props: ButtonProps<'button'>) {
  return (
    <FacebookLogin
      appId=''
      onSuccess={(response) => {
        console.log('Login Success!', response);
      }}
      onFail={(error) => {
        console.log('Login Failed!', error);
      }}
      onProfileSuccess={(response) => {
        console.log('Get Profile Success!', response);
      }}
    />
  );
}

Get white page after confirmation and won't close the popup

Hi,

I am using this to sign in with facebook and I get a white page in the popup after accepting the permission and it won't close and all confirmation don't work and when I close it i get status loginCancelled but it was not.

I do use API v13.0

Code to reproduce:

const handleResponse = (response) => {
  console.log("response", response)
}

return (
  <FacebookLogin
    appId="{APP_ID}"
    initParams={{
      version: 'v13.0',
      xfbml: true,
    }}
    scope="public_profile,instagram_basic,instagram_manage_insights,pages_read_engagement,pages_show_list"
    onFail={(e) => console.log('error', e)}
    onSuccess={handleResponse}
    onProfileSuccess={handleResponse}
  />
)

Facebook app only have Facebook login and Instagram app enabled. With correct redirect uri and Login with the JavaScript SDK set to Yes.

The page in the popup window get white/gray after clicking Continue As ... or Continue at the popup

Popup not opening in all browser?

Hello, I am using this plugin and react-messenger-chat-plugin` together in my project. Because my project have messenger chat and facebook login features. When I use this two plugin together then in facebook login component onclick do not open any popup. You can check up it here - https://www.nekmart.com/users/login.

Instead of messenger plugin I use messenger script-

<div id="fb-root"></div>
            <div id="fb-customer-chat" className="fb-customerchat"></div>
            <Script id="facebook-messenger1" dangerouslySetInnerHTML={{
              __html: `var chatbox = document.getElementById('fb-customer-chat');
              chatbox.setAttribute("page_id", "app_id");
              chatbox.setAttribute("attribution", "biz_inbox");`
            }} />
            <Script
              id="facebook-messenger"
              dangerouslySetInnerHTML={{
                __html: `
                window.fbAsyncInit = function() {
                  FB.init({
                    xfbml: true,
                    version: 'v15.0'
                  });
        };
  
                (function(d, s, id) {
          var js, fjs = d.getElementsByTagName(s)[0];
                if (d.getElementById(id)) return;
                js = d.createElement(s); js.id = id;
                js.src = 'https://connect.facebook.net/en_US/sdk/xfbml.customerchat.js';
                fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
            `,
              }}
            />

I am getting same problem popup not opening. Please suggest me how can I solve this kind of issue.

If there is no way to use this plugin together, Then I have to use useRedirect. If I use useRedirect then how can I find acesssToken and where?

Overriding current access token | Error

Hello, I'm encountering the following error after clicking the Facebook Login button. Just a basic implementation as suggested in the docs. The popup opens and closes immediately.

Any ideas?

Thanks a lot.

You are overriding current access token, that means some other app is expecting different access token and you will probably break things. Please consider passing access_token directly to API parameters instead of overriding the global settings.

Why is the pop-up not closing after successfully logging in?

The pop-up does not close after a successful log-in. The pop-up stays open and you can browse your facebook content in the pop-up.


I'm developing in localhost:3000 with HTTPS=true set in package.json

import React, { useEffect } from 'react';
import { ButtonProps } from '@mantine/core';
import FacebookLogin from '@greatsumini/react-facebook-login';

export function FacebookButton(props: ButtonProps<'button'>) {
  return (
    <FacebookLogin
      appId=''
      onSuccess={(response) => {
        console.log('Login Success!', response);
      }}
      onFail={(error) => {
        console.log('Login Failed!', error);
      }}
      onProfileSuccess={(response) => {
        console.log('Get Profile Success!', response);
      }}
    />
  );
}

TypeError: Failed to fetch

Hello,

I am using NextJS and trying the lib to use FacebookLogin, however I am having this issue, I am not sure if this an issue with v.15 api of facebook, these are my settings

The weird thing, is that I am able to log in and get information that is needed, but every time I click on the icon I get that error. any ideas as to why?

image

image

Force to show popup facebook and edit access button

Hi,

I'm working with business integrations and sometimes some permission is not selected by default.
For this reason, I need to force show the popup with Edit or Manage Permissions.

Can I force it?

Or can you add a function like beforeLogin where I can call a function to remove my business integration?

Thank you

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.