Skip to content

Commit

Permalink
Merge pull request #298 from MobilityData/280-troubleshoot-why-first-…
Browse files Browse the repository at this point in the history
…account-verification-email-doesnt-work-for-oauth-registered-accounts

fix: displayed an alert if no public email provided in Github account; ver…
  • Loading branch information
qcdyx authored Feb 19, 2024
2 parents 5a9f4e5 + 9de5ce0 commit b3a224d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion web-app/src/app/screens/PostRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function PostRegistration(): React.ReactElement {
) {
navigateTo(ACCOUNT_TARGET);
}
}, []);
}, [userProfileStatus]);

return (
<Container component='main' maxWidth='sm'>
Expand Down
42 changes: 39 additions & 3 deletions web-app/src/app/screens/SignUp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,19 @@ import { useNavigate } from 'react-router-dom';
import * as Yup from 'yup';
import { useFormik } from 'formik';
import { useAppDispatch } from '../hooks';
import { loginFail, loginWithProvider, signUp } from '../store/profile-reducer';
import { Alert, IconButton, InputAdornment, Tooltip } from '@mui/material';
import {
loginFail,
loginWithProvider,
signUp,
verifyEmail,
} from '../store/profile-reducer';
import {
Alert,
IconButton,
InputAdornment,
Snackbar,
Tooltip,
} from '@mui/material';
import { useSelector } from 'react-redux';
import {
ACCOUNT_TARGET,
Expand All @@ -38,6 +49,7 @@ import { VisibilityOffOutlined, VisibilityOutlined } from '@mui/icons-material';
export default function SignUp(): React.ReactElement {
const [showPassword, setShowPassword] = React.useState(false);
const [showConfirmPassword, setShowConfirmPassword] = React.useState(false);
const [showNoEmailSnackbar, setShowNoEmailSnackbar] = React.useState(false);

const navigateTo = useNavigate();
const dispatch = useAppDispatch();
Expand Down Expand Up @@ -105,7 +117,14 @@ export default function SignUp(): React.ReactElement {
const provider = oathProviders[oauthProvider];
signInWithPopup(auth, provider)
.then((userCredential: UserCredential) => {
dispatch(loginWithProvider({ oauthProvider, userCredential }));
if (!userCredential.user.emailVerified) {
dispatch(verifyEmail());
}
if (userCredential.user.email == null) {
setShowNoEmailSnackbar(true);
} else {
dispatch(loginWithProvider({ oauthProvider, userCredential }));
}
})
.catch((error) => {
dispatch(
Expand Down Expand Up @@ -134,6 +153,23 @@ export default function SignUp(): React.ReactElement {

return (
<Container component='main' maxWidth='xs'>
<Snackbar
open={showNoEmailSnackbar}
anchorOrigin={{ vertical: 'top', horizontal: 'center' }}
onClose={() => {
setShowNoEmailSnackbar(false);
}}
>
<Alert
severity='error'
onClose={() => {
setShowNoEmailSnackbar(false);
}}
>
No public email provided in Github account. Please use a different
registration method.
</Alert>
</Snackbar>
<CssBaseline />
<Box
sx={{
Expand Down

0 comments on commit b3a224d

Please sign in to comment.