Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Facebook Login #126

Merged
merged 6 commits into from
Dec 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions gatsby-theme-firebase/src/components/SocialLogins.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {
googleProvider,
githubProvider,
twitterProvider,
facebookProvider,
} from "../firebase/auth";
import SocialLoginButton from "./SocialLoginButton";
import GitHubIcon from "./icons/GitHub";
import GoogleIcon from "./icons/Google";
import TwitterIcon from "./icons/Twitter";
import FacebookIcon from "./icons/Facebook";

const SocialLogins: React.FunctionComponent<{
onSuccess?: (user?: firebase.auth.UserCredential) => void;
Expand All @@ -21,6 +23,7 @@ const SocialLogins: React.FunctionComponent<{
const enableGoogle = socialLogins.includes("google");
const enableTwitter = socialLogins.includes("twitter");
const enableGitHub = socialLogins.includes("github");
const enableFacebook = socialLogins.includes("facebook");

return (
<div
Expand Down Expand Up @@ -63,6 +66,21 @@ const SocialLogins: React.FunctionComponent<{
<TwitterIcon sx={{ mr: 1 }} size={18} /> Sign in with Twitter
</SocialLoginButton>
)}
{enableFacebook && (
nerdogram marked this conversation as resolved.
Show resolved Hide resolved
<SocialLoginButton
onClick={async () => {
try {
const user = await auth.signInWithPopup(facebookProvider());
onSuccess(user);
} catch (err) {
console.error("Authentication Error: ", err);
onError(err);
}
}}
>
<FacebookIcon sx={{ mr: 1 }} size={18} /> Sign in with Facebook
</SocialLoginButton>
)}
{enableGitHub && (
<SocialLoginButton
onClick={async () => {
Expand Down
24 changes: 24 additions & 0 deletions gatsby-theme-firebase/src/components/icons/Facebook.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import * as React from "react";

interface Props extends React.SVGAttributes<SVGElement> {
size?: number;
}

const Faceboook: React.FunctionComponent<Props> = ({
size = 16,
...restProps
}) => {
return (
<svg width={size} height={size} viewBox="0 0 50 50" {...restProps}>
<title>Faceboook</title>
<g fill="none" fillRule="evenodd">
<path
d="M40,0H10C4.486,0,0,4.486,0,10v30c0,5.514,4.486,10,10,10h30c5.514,0,10-4.486,10-10V10C50,4.486,45.514,0,40,0z M39,17h-3 c-2.145,0-3,0.504-3,2v3h6l-1,6h-5v20h-7V28h-3v-6h3v-3c0-4.677,1.581-8,7-8c2.902,0,6,1,6,1V17z"
fill="#3A5C98"
/>
</g>
</svg>
);
};

export default Faceboook;
4 changes: 4 additions & 0 deletions gatsby-theme-firebase/src/firebase/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ export const googleProvider = () => {
export const twitterProvider = () => {
return new firebase.auth.TwitterAuthProvider();
};

export const facebookProvider = () => {
return new firebase.auth.FacebookAuthProvider();
};