-
Notifications
You must be signed in to change notification settings - Fork 0
fix: junk email + email verification page #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| 'use client'; | ||
|
|
||
| import * as React from 'react'; | ||
| import CheckCircleOutlineIcon from '@mui/icons-material/CheckCircleOutline'; | ||
| import ErrorOutlineIcon from '@mui/icons-material/ErrorOutline'; | ||
| import { | ||
| Alert, | ||
| CircularProgress, | ||
| Stack, | ||
| Typography, | ||
| useTheme, | ||
| } from '@mui/material'; | ||
| import { useTranslations } from 'next-intl'; | ||
| import { app } from '../../../firebase'; | ||
| import { ContentBox } from '../../components/ContentBox'; | ||
|
|
||
| type VerificationStatus = 'loading' | 'success' | 'error'; | ||
|
|
||
| interface EmailVerificationContentProps { | ||
| mode?: string; | ||
| oobCode?: string; | ||
| } | ||
|
|
||
| export default function EmailVerificationContent({ | ||
| mode, | ||
| oobCode, | ||
| }: EmailVerificationContentProps): React.ReactElement { | ||
| const t = useTranslations('emailVerification'); | ||
| const theme = useTheme(); | ||
| const [status, setStatus] = React.useState<VerificationStatus>('loading'); | ||
| const [errorMessage, setErrorMessage] = React.useState<string | null>(null); | ||
|
|
||
| React.useEffect(() => { | ||
| const verifyEmail = async (): Promise<void> => { | ||
| if (mode !== 'verifyEmail' || oobCode == null || oobCode.length === 0) { | ||
| setStatus('error'); | ||
| setErrorMessage(t('invalidLink')); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| await app.auth().applyActionCode(oobCode); | ||
|
|
||
| setStatus('success'); | ||
| setErrorMessage(null); | ||
| } catch { | ||
| setStatus('error'); | ||
| setErrorMessage(t('verificationFailed')); | ||
| } | ||
| }; | ||
|
|
||
| void verifyEmail(); | ||
| }, [mode, oobCode]); | ||
|
|
||
| return ( | ||
| <ContentBox | ||
| title='' | ||
| sx={{ | ||
| display: 'flex', | ||
| justifyContent: 'center', | ||
| backgroundColor: theme.palette.background.paper, | ||
| maxWidth: theme.breakpoints.values.sm, | ||
| mx: 'auto', | ||
| mt: 6, | ||
| }} | ||
| > | ||
| <Stack spacing={3} alignItems='center' textAlign='center'> | ||
| {status === 'loading' ? ( | ||
| <CircularProgress aria-label={t('loadingTitle')} /> | ||
| ) : status === 'success' ? ( | ||
| <CheckCircleOutlineIcon color='success' sx={{ fontSize: 56 }} /> | ||
| ) : ( | ||
| <ErrorOutlineIcon color='error' sx={{ fontSize: 56 }} /> | ||
| )} | ||
|
|
||
| <Stack spacing={1.5}> | ||
| <Typography variant='h4' component='h1' sx={{ fontWeight: 700 }}> | ||
| {status === 'loading' | ||
| ? t('loadingTitle') | ||
| : status === 'success' | ||
| ? t('successTitle') | ||
| : t('errorTitle')} | ||
| </Typography> | ||
| <Typography variant='body1' color='text.secondary'> | ||
| {status === 'loading' | ||
| ? t('loadingDescription') | ||
| : status === 'success' | ||
| ? t('successDescription') | ||
| : t('errorDescription')} | ||
| </Typography> | ||
| </Stack> | ||
|
|
||
| {errorMessage != null && ( | ||
| <Alert severity='error' variant='outlined' sx={{ width: '100%' }}> | ||
| {errorMessage} | ||
| </Alert> | ||
| )} | ||
| </Stack> | ||
| </ContentBox> | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { type ReactElement } from 'react'; | ||
| import { setRequestLocale } from 'next-intl/server'; | ||
| import { type Metadata } from 'next'; | ||
| import { type Locale, routing } from '../../../i18n/routing'; | ||
| import EmailVerificationContent from './EmailVerificationContent'; | ||
|
|
||
| export const metadata: Metadata = { | ||
| title: 'Email Verification | MobilityDatabase', | ||
| description: | ||
| 'Verify your Mobility Database account email address through Firebase authentication.', | ||
| robots: { | ||
| index: false, | ||
| follow: false, | ||
| googleBot: { | ||
| index: false, | ||
| follow: false, | ||
| 'max-image-preview': 'none', | ||
| 'max-snippet': -1, | ||
| 'max-video-preview': -1, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| export function generateStaticParams(): Array<{ | ||
| locale: Locale; | ||
| }> { | ||
| return routing.locales.map((locale) => ({ locale })); | ||
| } | ||
|
|
||
| interface PageProps { | ||
| params: Promise<{ locale: string }>; | ||
| searchParams: Promise<{ | ||
| mode?: string; | ||
| oobCode?: string; | ||
| }>; | ||
|
Comment on lines
+30
to
+35
|
||
| } | ||
|
|
||
| export default async function EmailVerificationPage({ | ||
| params, | ||
| searchParams, | ||
| }: PageProps): Promise<ReactElement> { | ||
| const { locale } = await params; | ||
| const { mode, oobCode } = await searchParams; | ||
|
|
||
| setRequestLocale(locale as Locale); | ||
|
|
||
|
||
| return <EmailVerificationContent mode={mode} oobCode={oobCode} />; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.