mirror of
https://github.com/kevin-DL/commander_league_web.git
synced 2026-01-11 18:14:27 +00:00
Initial commit from Create Next App
This commit is contained in:
54
components/FirebaseAuth.js
Normal file
54
components/FirebaseAuth.js
Normal file
@@ -0,0 +1,54 @@
|
||||
/* globals window */
|
||||
import { useEffect, useState } from 'react'
|
||||
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth'
|
||||
import firebase from 'firebase/app'
|
||||
import 'firebase/auth'
|
||||
import initFirebase from '../utils/auth/initFirebase'
|
||||
import { setUserCookie } from '../utils/auth/userCookies'
|
||||
import { mapUserData } from '../utils/auth/mapUserData'
|
||||
|
||||
// Init the Firebase app.
|
||||
initFirebase()
|
||||
|
||||
const firebaseAuthConfig = {
|
||||
signInFlow: 'popup',
|
||||
// Auth providers
|
||||
// https://github.com/firebase/firebaseui-web#configure-oauth-providers
|
||||
signInOptions: [
|
||||
{
|
||||
provider: firebase.auth.EmailAuthProvider.PROVIDER_ID,
|
||||
requireDisplayName: false,
|
||||
},
|
||||
],
|
||||
signInSuccessUrl: '/',
|
||||
credentialHelper: 'none',
|
||||
callbacks: {
|
||||
signInSuccessWithAuthResult: async ({ user }, redirectUrl) => {
|
||||
const userData = mapUserData(user)
|
||||
setUserCookie(userData)
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}, [])
|
||||
return (
|
||||
<div>
|
||||
{renderAuth ? (
|
||||
<StyledFirebaseAuth
|
||||
uiConfig={firebaseAuthConfig}
|
||||
firebaseAuth={firebase.auth()}
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default FirebaseAuth
|
||||
Reference in New Issue
Block a user