-
Notifications
You must be signed in to change notification settings - Fork 450
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dashboard: restrict signup/signin to verified emails only (#2610)
resolves #2585
- Loading branch information
Showing
4 changed files
with
121 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@nhost/dashboard': minor | ||
--- | ||
|
||
feat: refactor sign-in and sign-up pages to enforce email verification |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import { NavLink } from '@/components/common/NavLink'; | ||
import { UnauthenticatedLayout } from '@/components/layout/UnauthenticatedLayout'; | ||
import { Box } from '@/components/ui/v2/Box'; | ||
import { Button } from '@/components/ui/v2/Button'; | ||
import { Text } from '@/components/ui/v2/Text'; | ||
import { getToastStyleProps } from '@/utils/constants/settings'; | ||
import { useNhostClient } from '@nhost/nextjs'; | ||
import { useRouter } from 'next/router'; | ||
import { useEffect, useState, type ReactElement } from 'react'; | ||
import { toast } from 'react-hot-toast'; | ||
|
||
export default function VerifyEmailPage() { | ||
const router = useRouter(); | ||
const nhost = useNhostClient(); | ||
|
||
const { | ||
query: { email }, | ||
} = router; | ||
|
||
const [resendVerificationEmailLoading, setResendVerificationEmailLoading] = | ||
useState(false); | ||
|
||
useEffect(() => { | ||
if (!email) { | ||
router.push('/signin'); | ||
} | ||
}, [email, router]); | ||
|
||
const resendVerificationEmail = async () => { | ||
setResendVerificationEmailLoading(true); | ||
|
||
try { | ||
await nhost.auth.sendVerificationEmail({ email: email as string }); | ||
|
||
toast.success( | ||
`An new email has been sent to ${email}. Please follow the link to verify your email address and to | ||
complete your registration.`, | ||
getToastStyleProps(), | ||
); | ||
} catch { | ||
toast.error( | ||
'An error occurred while sending the verification email. Please try again.', | ||
getToastStyleProps(), | ||
); | ||
} finally { | ||
setResendVerificationEmailLoading(false); | ||
} | ||
}; | ||
|
||
return ( | ||
<> | ||
<Text | ||
variant="h2" | ||
component="h1" | ||
className="text-center text-3.5xl font-semibold lg:text-4.5xl" | ||
> | ||
Verify your email | ||
</Text> | ||
|
||
<Box className="grid grid-flow-row gap-4 rounded-md border bg-transparent p-6 lg:p-12"> | ||
<div className="relative py-2"> | ||
<Text color="secondary" className="text-center text-sm"> | ||
Please check your inbox for the verification email. Follow the link | ||
to verify your email address and complete your registration. | ||
</Text> | ||
</div> | ||
<Button | ||
className="!bg-white !text-black disabled:!text-black disabled:!text-opacity-60" | ||
size="large" | ||
disabled={resendVerificationEmailLoading} | ||
loading={resendVerificationEmailLoading} | ||
type="button" | ||
onClick={resendVerificationEmail} | ||
> | ||
Resend verification email | ||
</Button> | ||
|
||
<div className="flex justify-center"> | ||
<NavLink href="/signin" color="white" className="font-medium"> | ||
Sign In | ||
</NavLink> | ||
</div> | ||
</Box> | ||
</> | ||
); | ||
} | ||
|
||
VerifyEmailPage.getLayout = function getLayout(page: ReactElement) { | ||
return ( | ||
<UnauthenticatedLayout title="Verify your email"> | ||
{page} | ||
</UnauthenticatedLayout> | ||
); | ||
}; |
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
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