/** @jsx jsx */ import { jsx } from "theme-ui"; import * as React from "react"; import useFirebaseConfig from "../hooks/useFirebaseConfig"; import { auth } from "../firebase"; 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; onError?: (err: any) => void; }> = ({ onSuccess = () => {}, onError = () => {}, ...restProps }) => { const { socialLogins } = useFirebaseConfig(); const enableGoogle = socialLogins.includes("google"); const enableTwitter = socialLogins.includes("twitter"); const enableGitHub = socialLogins.includes("github"); const enableFacebook = socialLogins.includes("facebook"); return (
{enableGoogle && ( { try { const user = await auth.signInWithPopup(googleProvider()); onSuccess(user); } catch (err) { console.error("Authentication Error: ", err); onError(err); } }} > Sign in with Google )} {enableTwitter && ( { try { const user = await auth.signInWithPopup(twitterProvider()); onSuccess(user); } catch (err) { console.error("Authentication Error: ", err); onError(err); } }} > Sign in with Twitter )} {enableFacebook && ( { try { const user = await auth.signInWithPopup(facebookProvider()); onSuccess(user); } catch (err) { console.error("Authentication Error: ", err); onError(err); } }} > Sign in with Facebook )} {enableGitHub && ( { try { const user = await auth.signInWithPopup(githubProvider()); onSuccess(user); } catch (err) { console.error("Authentication Error: ", err); onError(err); } }} > Sign in with Github )}
); }; export default SocialLogins;