mirror of
https://github.com/kevin-DL/commander_league_web.git
synced 2026-01-11 18:14:27 +00:00
58 lines
1.5 KiB
JavaScript
58 lines
1.5 KiB
JavaScript
/* 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,
|
|
},
|
|
{
|
|
provider: firebase.auth.GoogleAuthProvider.PROVIDER_ID,
|
|
},
|
|
],
|
|
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;
|