-
-
Save vpaladino778/86385ef171ecf440178f7298b728723c to your computer and use it in GitHub Desktop.
This file contains 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
import { Grid } from '@mui/material'; | |
import React, { useEffect, useState } from 'react'; | |
import { withAuthUser, AuthAction, withAuthUserTokenSSR } from 'next-firebase-auth' | |
import firebase from 'firebase/compat/app'; | |
import 'firebase/compat/auth'; | |
import StyledFirebaseAuth from 'react-firebaseui/StyledFirebaseAuth' | |
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: { | |
// https://github.com/firebase/firebaseui-web#signinsuccesswithauthresultauthresult-redirecturl | |
signInSuccessWithAuthResult: () => | |
// Don't automatically redirect. We handle redirects using | |
// `next-firebase-auth`. | |
false, | |
}, | |
} | |
const LoginPage = () => { | |
const [renderAuth, setRenderAuth] = useState(false); | |
useEffect(() => { | |
if (typeof window !== "undefined") { | |
setRenderAuth(true); | |
} | |
}, []); | |
return ( | |
<> | |
<Grid container spacing={2} direction="column" alignItems="center"> | |
<StyledFirebaseAuth | |
uiConfig={firebaseAuthConfig} | |
firebaseAuth={firebase.auth()} | |
/> | |
</Grid> | |
</> | |
); | |
}; | |
export const getServerSideProps = withAuthUserTokenSSR({ | |
whenAuthed: AuthAction.REDIRECT_TO_APP, | |
})() | |
export default withAuthUser({ | |
whenAuthed: AuthAction.REDIRECT_TO_APP, | |
})(LoginPage) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment