Giter VIP home page Giter VIP logo

react-social-login-buttons's Introduction

React Social Login Buttons

Live demo https://codesandbox.io/s/3rpq558rv5

A simple package to display social login buttons using React.

Buttons do not provide any social logic. They are only visual components listening to some events triggered by the user.

Social login buttons

Install

npm

npm install --save react-social-login-buttons

yarn

yarn add react-social-login-buttons

Importing

ES6 imports:

import { FacebookLoginButton } from "react-social-login-buttons";

ES6 imports optimized (deprecated):

import FacebookLoginButton from "react-social-login-buttons/lib/buttons/FacebookLoginButton";

Usage

Default button content - "Log in with Facebook"

<FacebookLoginButton onClick={() => alert("Hello")} />

Custom button content

<FacebookLoginButton onClick={() => alert("Hello")}>
  <span>Custom text</span>
</FacebookLoginButton>

Social Button Types

We currently support just a few login buttons. Others will be implemented later.

FacebookLoginButton

<FacebookLoginButton onClick={() => alert("Hello")} />

GoogleLoginButton

<GoogleLoginButton onClick={() => alert("Hello")} />

GithubLoginButton

<GithubLoginButton onClick={() => alert("Hello")} />

TwitterLoginButton

<TwitterLoginButton onClick={() => alert("Hello")} />

XLoginButton

<XLoginButton onClick={() => alert("Hello")} />

AmazonLoginButton

<AmazonLoginButton onClick={() => alert("Hello")} />

InstagramLoginButton

<InstagramLoginButton onClick={() => alert("Hello")} />

LinkedInLoginButton

<LinkedInLoginButton onClick={() => alert("Hello")} />

MicrosoftLoginButton

<MicrosoftLoginButton onClick={() => alert("Hello")} />

BufferLoginButton

<BufferLoginButton onClick={() => alert("Hello")} />

TelegramLoginButton

<TelegramLoginButton onClick={() => alert("Hello")} />

AppleLoginButton

<AppleLoginButton onClick={() => alert("Hello")} />

DiscordLoginButton

<DiscordLoginButton onClick={() => alert("Hello")} />

SlackLoginButton

<SlackLoginButton onClick={() => alert("Hello")} />

OktaLoginButton

<OktaLoginButton onClick={() => alert("Hello")} />

YahooLoginButton

<YahooLoginButton onClick={() => alert("Hello")} />

ZaloLoginButton

<ZaloLoginButton onClick={() => alert("Hello")} />

TikTokLoginButton

<TikTokLoginButton onClick={() => alert("Hello")} />

MetamaskLoginButton

<MetamaskLoginButton onClick={() => alert("Hello")} />

GitlabLoginButton

<GitlabLoginButton onClick={() => alert("Hello")} />

Create your own button

You can create your own button.

You do not have to wait for us to implement all of them.

You can also use your own icons, let's say from font-awesome.

You can also pass a component to the icon prop.

import React from "react";
import { createButton } from "react-social-login-buttons";

const config = {
  text: "Log in with Facebook",
  icon: "facebook",
  iconFormat: (name) => `fa fa-${name}`,
  style: { background: "#3b5998" },
  activeStyle: { background: "#293e69" },
};
/** My Facebook login button. */
const MyFacebookLoginButton = createButton(config);

export default MyFacebookLoginButton;

Config can also look like.

const config = {
  text: "Log in with Facebook",
  icon: MyIconComponent,
  style: { background: "#3b5998" },
  activeStyle: { background: "#293e69" },
};

Props

Props for every Button

onClick {function} (optional)

Will be triggered when clicked on the button.

style {Object} (optional)

Custom button styles

className {String} (optional)

Custom button class

children {React.children} (optional)

You can pass any children to our buttons.

activeStyle {Object} (optional)

activeStyle styles will be applied instead of style when mouse hovers above the element

icon {String|Node} (optional)

This icon will be displayed.

If you pass a string, <i className={format(name)}/> will be rendered.

iconSize {String} (optional)

Icon will have this size. Eg. "26px"

iconColor {String} (optional)

Icon will have this color - default #FFFFFF

size {String} (optional)

Box will have this size. Eg. "150px"

iconFormat {function} (optional)

Format icon className. Eg. (name) => "fa-icon fa-icon-" + name

align {"left" | "right" | "center"} (optional)

Align the text on the button (default is left).

preventActiveStyles {Boolean} (optional) default: false

If set to true, activeStyles won't be used and will be used styles from the style prop.

disabled {Boolean} (optional)

Disables (or enables the button)

Events

  • onClick
  • onMouseEnter
  • onMouseLeave

Why react-social-login-buttons ?

react-social-login-buttons is focused on speed and simplicity.

Contribution

I welcome issues and pull requests on https://github.com/michaeljscript/react-social-login-buttons

Thanks

Special thanks to people creating awesome svg icons and teams

react-social-login-buttons's People

Contributors

abdulrhmnghanem avatar antoinejaussoin avatar celian-garcia avatar csabhi1 avatar daggmano avatar danarth avatar dependabot[bot] avatar emadunan avatar gaurishhs avatar junaidatique avatar leopucci avatar michaeljscript avatar navedqb avatar roadsidev avatar saosangmo avatar shripadk avatar slhawkins avatar taha-azzabi avatar tazisydney123 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  avatar

react-social-login-buttons's Issues

Does not work with Expo

I am not able to make this component work with Expo. I get an error message

Unable to resolve module !!../../../node_modules/css-loader/index.js!./social-login-font.css from /Users/xxx/node_modules/react-social-login-buttons/lib/fontello-social/css/social-login-font-css.js` Module does not exist in the module map

LoginButton not tab-able

I use the Login Buttons in a react-bootstrap Modal. Inside the Modal, I can circle-tab through all elements like Buttons or Input fields, but the Login Buttons are not tab-able, meaning they do not get selected when using TAB.

I tried playing around with autoFocus or setting tabindex=1, but it doesn't work. Any suggestions how to solve that issue?

Change text from Login to Log in

Call me a grammar Nazi, but the default texts should be "Log in", not "Login".

Login, spelled as one word, is only a noun or an adjective. For example, the information you use to sign into your email is your login (noun), and the page where you sign in is the login page (adjective). Log in is two words when it functions as a verb. For example, you log in with your login information.

-- https://grammarist.com/spelling/log-in-login/

Cannot create icon for custom button

Trying to create a custom button:

import svgIcon from "../assets/email.svg"

const emailButtonConfig = {
        text: "Log in with Email",
        icon: createSvgIcon(svgIcon),
        iconFormat: name => `fa fa-${name}`,
        style: { background: "darkgray" },
        activeStyle: { background: "gray" }
    };

    const EmailLoginButton = createButton(emailButtonConfig);

This creates a button with no icon. The HTML generated for the icon is:

<button type="button" style="display: block; border: 0px; border-radius: 3px; box-shadow: rgba(0, 0, 0, 0.5) 0px 1px 2px; color: rgb(255, 255, 255); cursor: pointer; font-size: 19px; margin: 5px; width: calc(100% - 10px); overflow: hidden; padding: 0px 10px; user-select: none; height: 50px; background: darkgray;">
<div style="align-items: center; display: flex; height: 100%;">
<div style="display: flex; justify-content: center; min-width: 26px;"></div>
<div style="width: 10px;"></div>
<div style="text-align: left; width: 100%;">Log in with Email</div>
</div>
</button>

The div where the icon would be has no inner HTML. What am I doing wrong? I have tried putting the contents of "email.svg" into a string and passing that to createSvgIcon but that doesn't work either.

Does not support SSR (server-side rendering)

$ node build/server.js
\node_modules\react-social-login-buttons\lib\fontello-social\css\social-login-font.css.js:249
return window && document && document.all && !window.atob;
^

ReferenceError: window is not defined
at \node_modules\react-social-login-buttons\lib\fontello-social\css\social-login-font.css.js:249:2
at \node_modules\react-social-login-buttons\lib\fontello-social\css\social-login-font.css.js:238:46
at module.exports (\node_modules\react-social-login-buttons\lib\fontello-social\css\social-login-font.css.js:283:46)
at Object. (\node_modules\react-social-login-buttons\lib\fontello-social\css\social-login-font.css.js:87:36)
at webpack_require (\node_modules\react-social-login-buttons\lib\fontello-social\css\social-login-font.css.js:20:30)
at module.exports (\node_modules\react-social-login-buttons\lib\fontello-social\css\social-login-font.css.js:63:18)
at Object. (\node_modules\react-social-login-buttons\lib\fontello-social\css\social-login-font.css.js:66:10)
at Module._compile (internal/modules/cjs/loader.js:678:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:689:10)
at Module.load (internal/modules/cjs/loader.js:589:32)
error Command failed with exit code 1.

Can it work with styled-components?

Hi. Is there a way to style the buttons using styled-components library?

I'm trying the following, but it doesn't seem to work:

import styled from "styled-components";
import {
  FacebookLoginButton,
} from "react-social-login-buttons";

export const FacebookButton = styled(FacebookLoginButton)`
  width: 150px;
`;

Thanks.

Typescript definitions

This is a great module for social login and custom buttons. Is there any plans to support Typescript in the future? Maybe there is a separate project for that I am not aware of?

Form is posting on button click on react - how to disable

Hi, thanks for your job on this component.
I am struggling with a feature, when I click on this button, it submits the form. other react buttons that I use they don´t submit, so you can use onClick function to make it work.
I know that it needs a preventDefault() somewhere, but I lack of react knowledge to know where.
If someone knows how to prevent the submit on react, would help me a lot.
I am creating this issue because this can help other users also (I guess :) )
Thanks
Pucci

v3.1.2: Google Login Button

First thanks for your hard work in providing this handy package,

I noticed when I upgraded to 3.1.2 that the Google button was not being rendered in the red styling that you created. It is instead falling back to the default style.

I tested this on both node 12 and 14, as I wasn't sure what the root cause was, but this is what I'm seeing:

Version 3.1.2, delete node_modules, re-install

image

Downgrade to Version 3.1.0, delete node_modules, re-install

image

It's possible there is some other factor at play, but I just wanted to validate that the new release has the correct content.

Custom button: icons doesn't load

Hello :)
I am writing this issue because I am unable to get a custom button with the button displaying an icon.

image
image

And if I test with createSvgIcon, I get the following error:
image
image

Is it on my side? Or is there something wrong with the dependency?
Thanks!

The buttons can't be used in React app

Hello,

I tried to create a component like

import * as React from "react";
import { GoogleLoginButton } from "react-social-login-buttons";

export class Auth extends React.Component<any, any> {
  public render() {
    return (
      <GoogleLoginButton onClick={() => alert("Hello)} />
    );
  }
}

But i got the errors:

[ts]
JSX element type 'GoogleLoginButton' is not a constructor function for JSX elements.
  Property 'render' is missing in type 'GoogleLoginButton'.
[ts] JSX element class does not support attributes because it does not have a 'props' property.

What I'm doing wrong?

Thanks!

Tomas

Not working with the latest react version

Cannot install the extension. It's peerDependency ia only react versions up to 17.x.x

npm i react-social-login-buttons
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/react
npm ERR! dev react@"^18.2.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^15.0.0 || ^16.0.0 || ^17.x" from [email protected]
npm ERR! node_modules/react-social-login-buttons
npm ERR! react-social-login-buttons@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Icons aren't showing up

Hi,

A bit of a newbie here, so probably I'm missing something which would be extremely obvious to someone else.

I'm using your social buttons together with the 'react-social-login' package.

The code looks something like this (just the relevant bits):

import { OldSocialLogin as SocialLogin } from 'react-social-login';
import GoogleLoginButton from 'react-social-login-buttons/lib/buttons/GoogleLoginButton';

class Login extends React.Component {
    defaults = {
        text: 'Login with Google',
        icon: 'google',
        iconFormat: name => `fa fa-${name}`,
        style: {background: "#3b5998"},
        activeStyle: {background: "#293e69"}
    };

    responseGoogle = (e) => {
        console.log(e);
    }

    render() {
        return (
            <div>
                <SocialLogin
                    defaults={this.defaults}
                    provider='google'
                    appId="app_id_goes_here :)"
                    callback={this.responseGoogle}
                >
                <GoogleLoginButton>Login with Google</GoogleLoginButton>
                </SocialLogin>
            </div>
        );
    }
}

I also tried without 'defaults'. No matter what I do, the icons do not appear, even though the rest of the button looks as expected.

I'll appreciate if you can help me a bit, as I said, a bit of a newbie here.

Thanks.

clientId

where insert ClientId? without ClientId how login with it?

Twitter uses old icon

Great package, thanks! Just mentioning that the Twitter logo used is the old one (beak pointing right). Your screenshot shows the new one (beak pointing up-right) but that isn't what outputs when I use this package. Thanks :-)

Can't use custom icon from font awesome

import React from "react";
import { createButton } from "react-social-login-buttons";
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import { faSignOutAlt } from "@fortawesome/free-solid-svg-icons";
import { createSvgIcon } from "react-social-login-buttons";

const Icon = props => <FontAwesomeIcon icon={faSignOutAlt} />;
const config = {
  text: "Logout",
  icon: Icon,
  iconFormat: name => `fa fa-${name}`,
  style: { background: "#3b5998" },
  activeStyle: { background: "#293e69" }
};
/** My Facebook login button. */
const LogOut = createButton(config);

export default LogOut;

Am I doing something wrong here?
I am passing in a component

Cannot find name 'ComponentClass' types error

After installing from npm and implementing I get:

TypeScript error in [...]/react-social-login-buttons/src/types.d.ts(48,72):
Cannot find name 'ComponentClass'. TS2304

I believe this issue has already been fixed in the bugfix/types branch, but somehow not yet merged to production.

Facebook login doesn't work when in ios webview

in particular: when clicked on a link on FB app, which is opened in the FB browser.
maybe connected to
https://stackoverflow.com/questions/37269888/facebook-login-is-not-working-in-app-browser-for-ios ?


Update:

please ignore, wrong repo.

Sign in with Apple Button

Are there any plans to add a Sign in with Apple button? Seems especially useful for web based iOS applications that are now required to include Sign in with Apple. I'd be happy to submit a PR.

Unable to npm install - ERESOLVE unable to resolve dependency tree

npm version: 7.5.4

pm ERR! Could not resolve dependency:
npm ERR! peer react@"^15.0.0 || ^16.0.0" from [email protected]
npm ERR! node_modules/react-social-login-buttons
npm ERR!   react-social-login-buttons@"*" from the root project
npm ERR! 
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR! 

Outdated Microsoft Logo Button

According to the standards that Microsoft has: Sign in with Microsoft: Branding guidelines for applications

This is how they should look.
image
image

But this is how they currently look.
image

I ended up not using this repository because it was easier to download the SVG and use it as a react component than to make a custom component with this library. No offense, I am just explaining what other people will end up doing because of the button being outdated.

Custom SVG icon not working

Hi

I am trying to include following SVG icon, but it is not working.

https://github.com/bufferapp/buffer-blog-v2/blob/master/wp-content/themes/buffer-v2/images/buffer-logomark.svg?short_path=ad18f60

my code is

import React from "react";
import { createButton, createSvgIcon } from "react-social-login-buttons";
import BufferIcon from "./icons/buffer.svg";

const icon = createSvgIcon(BufferIcon);

const config = {
  text: "Connect Instagram, LinkedIn",
  icon: icon,
  // iconFormat: name => `fa fa-${name}`,
  style: { background: "#CED7DF" },
  activeStyle: { background: "#293e69" }
};

export default createButton(config);

I am getting following error.

TypeError: Object(...) is not a function

on this line

const icon = createSvgIcon(BufferIcon);

Please help.

Thanks.

Uncaught TypeError: Cannot read property 'preventDefault' of undefined

I´m having some trouble using this button with https://github.com/A-Tokyo/react-apple-signin-auth
image

The module is trying to use preventDefault() from the form post but there is no post to be prevented. Maybe it is because of that.
image

The strange thing is that I use react-social-login-buttons with https://www.npmjs.com/package/react-google-login and works properly.

I 've opened an issue on the react-apple-signin-auth module, because I think that maybe there is no need to preventDefault on the module. But I don´t know why this module does not play well with it.
a-tokyo/react-apple-signin-auth#61

The strange is that if I use a single it works properly.
image

But if I use Apple button (or others from the module) it does not work.
image

Any ideas?
Thanks
Pucci

Demo is giving an error of "No valid scopes requested"

I've ran live demo which is given here its giving me an error that {"error_type": "OAuthException", "code": 400, "error_message": "No valid scopes requested"}

"react": "^18.2.0",
"reactjs-social-login": "^2.6.1",

Any help is appriciated.
Thank you.

Discord login button

Hey!
Love your project.

Lately been using the Discord auth method and I would love to keep using your package for this!

Hope you can add it sometime in the future.

Cheers

Cannot set `type="submit"` for button.

My use-case calls for the social button to submit a form when clicked. PR #58 set type="button" with no ability to override it.

I can submit a new PR to add a type prop which defaults to type="button".

Telegram Auth

Hi,

it would be super cool if you could add a button for Telegram. We use their login widget for authentication.

Cheers

createButton can't be used in TypeScript

Hello @MichalSzorad,

one more thing to fix in types is needed: add declaration for createButton function. If I try to import it this error is occured:

Could not find a declaration file for module 'react-social-login-buttons/lib/buttons/create-button'. '/Users/darbic/work-live/dev/aiteq-specialists/node_modules/react-social-login-buttons/lib/buttons/create-button.js' implicitly has an 'any' type.
Try `npm install @types/react-social-login-buttons` if it exists or add a new declaration (.d.ts) file containing `declare module 'react-social-login-buttons';`

Thanks.

Tomas

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.