
Security News
CVE Volume Surges Past 48,000 in 2025 as WordPress Plugin Ecosystem Drives Growth
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.
react-social-login
Advanced tools

React Social Login is an HOC which provides social login through multiple providers.
Currently supports Amazon, Facebook, GitHub, Google, Instagram and LinkedIn as providers (more to come!)
*LinkedIn has deprecated it's JS SDK. Hence, not supported anymore.
While this library does a good job of fetching basic profile, at times you might need to get additional attributes from providers like DateOfBirth, HomeTowm, etc. which aren't returned by default. Scopes are purely provider dependent and their documentation is the best place to look for supported scopes and literal to be passed as argument. You can pass those scopes using the scope tag. For example, if you want birth date from Facebook (which isn't returned by default), you'd add following scope to your tag:
scope = "user_birthday,user_hometown";
Below are some links to official scopes guide for a few providers:
See https://deepakaggarwal7.github.io/react-social-login.
Edit appId props with your own ones in demo/index.js file and build demo:
$ npm start
You can then view the demo at https://localhost:8080.
For GitHub provider, see GitHub specifics first.
$ npm install --save react-social-login
Create the component of your choice and transform it into a SocialLogin component.
SocialButton.js
import React from "react";
import SocialLogin from "react-social-login";
class SocialButton extends React.Component {
render() {
const { children, triggerLogin, ...props } = this.props;
return (
<button onClick={triggerLogin} {...props}>
{children}
</button>
);
}
}
export default SocialLogin(SocialButton);
Then, use it like a normal component.
index.js
import React from "react";
import ReactDOM from "react-dom";
import SocialButton from "./SocialButton";
const handleSocialLogin = (user) => {
console.log(user);
};
const handleSocialLoginFailure = (err) => {
console.error(err);
};
ReactDOM.render(
<div>
<SocialButton
provider="facebook"
appId="YOUR_APP_ID"
onLoginSuccess={handleSocialLogin}
onLoginFailure={handleSocialLoginFailure}
>
Login with Facebook
</SocialButton>
</div>,
document.getElementById("app")
);
There are times when initialization of a component can take longer than expected. To support these changes there is the optional loader component.
Simply pass the component as a second parameter to SocialLogin
SocialButton.js
import React from "react";
import SocialLogin from "react-social-login";
import Loading from "./Loading";
class SocialButton extends React.Component {
render() {
const { children, triggerLogin, ...props } = this.props;
return (
<button onClick={triggerLogin} {...props}>
{children}
</button>
);
}
}
export default SocialLogin(SocialButton, Loading);
Raw component props (before transform):
| Prop | Default | Type / Values | Description |
|---|---|---|---|
| appId | — | string | Your app identifier (see find my appId) |
| autoCleanUri | false | boolean | Enable auto URI cleaning with OAuth callbacks |
| autoLogin | false | boolean | Enable auto login on componentDidMount |
| gatekeeper | — | string | Gatekeeper URL to use for GitHub OAuth support (see GitHub specifics) |
| getInstance | — | function | Return node ref like ref function would normally do (react known issue) |
| onLoginFailure | — | function | Callback on login fail |
| onLoginSuccess | — | function | Callback on login success |
| onLogoutFailure | — | function | Callback on logout fail (google only) |
| onLogoutSuccess | — | function | Callback on logout success |
| onInternetFailure | — | function | Doesn't open popup if returns false and internet isn't there |
| provider | — | amazon, facebook, github, google, instagram, linkedin | Social provider to use |
| redirect | - | string | URL to redirect after login (available for github and instagram only) |
| scope | - | array, string | An array or string of scopes to be granted on login. |
| version | - | string | Can be used to explicitly specify FBsdk version (default is v5.0) |
| any other prop | — | — | Any other prop will be forwarded to your component |
Note about redirect: if you are redirecting on root (eg: https://localhost:8080), you have to omit the trailing slash.
Transformed component props:
| Prop | Type | Description |
|---|---|---|
| triggerLogin | function | Function to trigger login process, usually attached to an event listener |
| triggerLogout | function | Function to trigger logout process, usually attached to a container handling login state |
| all your props | — | All props from your original component, minus SocialLogin specific props |
To implement logout, we need a container handling login state and triggering logout function from a ref to SocialLogin component.
As it is implemented in the demo, we have two components working together to trigger logout:
Here is how they work together:
Demo is displaying UserCard only if user is loggedUserCard gets forwarded a logout functionUserCard calls forwarded logout prop on click on the logout buttonlogout function triggers triggerLogout prop from a ref to SocialLogin componentWe decided to keep the old behavior as a fallback, it only supports facebook, google and linkedin providers and is available as a named export:
import React from "react";
import ReactDOM from "react-dom";
import { OldSocialLogin as SocialLogin } from "react-social-login";
const handleSocialLogin = (user, err) => {
console.log(user);
console.log(err);
};
ReactDOM.render(
<div>
<SocialLogin
provider="facebook"
appId="YOUR_APP_ID"
callback={handleSocialLogin}
>
<button>Login with Google</button>
</SocialLogin>
</div>,
document.getElementById("app")
);
Though not mandatory, it is recommended to use latest npm5 to match lockfile versions.
$ npm install
$ npm run build
See Amazon developers documentation.
See facebook for developers documentation.
See Google Sign-In for Websites guide.
See Instagram developers documentation.
See Where can I find my API key? section on the FAQ.
GitHub provider is implemented in two different modes:
Actually, this one is more a hacky way to get user profile than a way to really connect your app like OAuth does.
Plus, it requires from users to create their personal token from their GitHub account, which is not a good experience for them.
This mode is the default if you do not provide gatekeeper prop and will try to use the appId prop to get user data. Anyway, we strongly advise you to use the GitHub OAuth authentication flow.
If you provide a gatekeeper prop, this mode will be active and will use a server of your own to fetch GitHub OAuth access token. This is a know issue of GitHub.
The simplest way to setup this mode is to use the Gatekeeper project. Just follow setup instructions then tell RSL to use it:
<SocialLogin
provider='github'
gatekeeper='http://localhost:9999'
appId='YOUR_GITHUB_CLIENT_ID'
redirect='http://localhost:8080'
>
Login with GitHub OAuth
</SocialLogin>
You can also implement it your own way but you must use the same routing than Gatekeeper (/authenticate/:code) and return a JSON response containing a token or error property (it will also throw if it doesn't find token).
RSL demo is served over https with webpack-dev-server. This is a requirement of Amazon Login SDK. Gatekeeper is served over insecure http so you will have to serve the demo through http also to work with GitHub (but it will break Amazon):
$ npm run start:insecure
v2.0.0 [26 Feb 2017]
v2.0.1 [24 June 2017] merged pull request #15
v3.0.0 [30 July 2017] merged pull request #19
v3.1.0 [01 August 2017] merged pull request #20
v3.2.0 [14 September 2017] 3.2.0
v3.2.1 [06 October 2017] React 16, better build, update dep, additions and fixes
v3.3.0 [22 October 2017] Logout, custom scopes and fixes
v3.4.0 [22 October 2017] Fix logout issues, expose wrapped component ref and fixes
v3.4.1 [08 November 2017] Fix logout issues, adds SSR support and fixes
triggerLogout forwarded to wrapped componentv3.4.2 [26 December 2017] Fix SSR, refs and update build
babel-preset-env, updated dependencies, lighter npm package)v3.4.3 [23 December 2018] merged pull request #112
v3.4.5 [25 Sep 2019] merged pull request #135
v3.4.6 [30 Oct 2019] merged pull request, logo added #143
v3.4.7 [07 May 2020] Fb version upgrade, more control on github scopes
v3.4.8 [07 July 2020] Gender pulled for Google
v3.4.9 [03 August 2020] types included in dist and example functional component added
v3.4.10 [30 September 2020] types included in dist and example functional
v3.4.13 [06 March 2021] onInternetFailure, explicit FB version, Webpack
v3.4.14 [25 Jul 2021] merged pr/122
v3.4.15 [26 Dec 2021] merged pr/219
v3.4.16 [26 Nov 2022]
TBD
FAQs
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
CVE disclosures hit a record 48,185 in 2025, driven largely by vulnerabilities in third-party WordPress plugins.

Security News
Socket CEO Feross Aboukhadijeh joins Insecure Agents to discuss CVE remediation and why supply chain attacks require a different security approach.

Security News
Tailwind Labs laid off 75% of its engineering team after revenue dropped 80%, as LLMs redirect traffic away from documentation where developers discover paid products.