Created
October 20, 2020 21:23
-
-
Save stevengrimaldo/9036c849dee9a5db0f4945ba24da588d to your computer and use it in GitHub Desktop.
Firebase + Google Sign in CTA & Functionality
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* globals window */ | |
import React, { useEffect, useState } from 'react' | |
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth' | |
import firebase from 'firebase/app' | |
import 'firebase/auth' | |
import initFirebase from '../global/auth/initFirebase' | |
import { setUserCookie } from '../global/auth/userCookies' | |
import { mapUserData } from '../global/auth/mapUserData' | |
// Init the Firebase app. | |
initFirebase() | |
const firebaseAuthConfig = { | |
callbacks: { | |
signInSuccessWithAuthResult: async ({ user }, _) => { | |
const userData = mapUserData(user) | |
setUserCookie(userData) | |
}, | |
}, | |
credentialHelper: 'none', | |
signInFlow: 'popup', | |
// Auth providers | |
// https://github.com/firebase/firebaseui-web#configure-oauth-providers | |
signInOptions: [firebase.auth.GoogleAuthProvider.PROVIDER_ID], | |
signInSuccessUrl: '/', | |
} | |
const FirebaseAuth = () => { | |
// Do not SSR FirebaseUI, because it is not supported. | |
// https://github.com/firebase/firebaseui-web/issues/213 | |
const [renderAuth, setRenderAuth] = useState(false) | |
useEffect(() => { | |
if (typeof window !== 'undefined') { | |
setRenderAuth(true) | |
} | |
}, []) | |
renderAuth ? return ( | |
<StyledFirebaseAuth | |
uiConfig={firebaseAuthConfig} | |
firebaseAuth={firebase.auth()} | |
/> | |
) : return null | |
} | |
export default FirebaseAuth |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment