Skip to content

Instantly share code, notes, and snippets.

@vpaladino778
Created December 17, 2021 14:12
Show Gist options
  • Save vpaladino778/86385ef171ecf440178f7298b728723c to your computer and use it in GitHub Desktop.
Save vpaladino778/86385ef171ecf440178f7298b728723c to your computer and use it in GitHub Desktop.
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