-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add forgot password page #155
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
Merged
Merged
Changes from 11 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
206e013
feat: Add ForgotPasswordForm and create request procedure
ZeroWave022 52093c0
feat: Update react-email and fix email background styling
ZeroWave022 99299e4
fix: Reorder size and index in OTPField
ZeroWave022 80ff10e
feat: Make InputOtp slightly more responsive
ZeroWave022 2e55919
feat: Add new password form page with OTP input
ZeroWave022 a28f655
fix: Use PNGs instead of SVGs in emails for better support
ZeroWave022 0549d64
docs: Token Bucket classes and Throttler
ZeroWave022 14c1e3e
feat: Add API rate limiting to forgot password
ZeroWave022 65922d4
fix: Retry id creation if it already exists
ZeroWave022 9bfdcb9
Merge branch 'dev' into feat/forgot-password
ZeroWave022 3b5a5de
chore: Update bun lockfile
ZeroWave022 733063d
feat: Add info toast to forgot password requests
ZeroWave022 4d1285f
fix: Regex for password containing at least one lowercase letter
ZeroWave022 bdde313
fix: Check if forgot password request has already been used
ZeroWave022 d56e07f
chore: Add DB migration for forgot password requests
ZeroWave022 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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
30 changes: 30 additions & 0 deletions
30
src/app/[locale]/auth/forgot-password/[requestId]/page.tsx
This file contains hidden or 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,30 @@ | ||
| import type { Locale } from 'next-intl'; | ||
| import { getTranslations, setRequestLocale } from 'next-intl/server'; | ||
| import { NewPasswordForm } from '@/components/auth/NewPasswordForm'; | ||
| import { api } from '@/lib/api/server'; | ||
| import { redirect } from '@/lib/locale/navigation'; | ||
|
|
||
| export async function generateMetadata() { | ||
| const t = await getTranslations('layout'); | ||
|
|
||
| return { | ||
| title: t('forgotPassword'), | ||
| }; | ||
| } | ||
|
|
||
| export default async function ForgotPasswordRequestPage({ | ||
| params, | ||
| }: { | ||
| params: Promise<{ locale: Locale; requestId: string }>; | ||
| }) { | ||
| const { locale, requestId } = await params; | ||
| setRequestLocale(locale); | ||
|
|
||
| const { user } = await api.auth.state(); | ||
|
|
||
| if (user) { | ||
| redirect({ href: '/', locale }); | ||
| } | ||
|
|
||
| return <NewPasswordForm requestId={requestId} />; | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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,95 @@ | ||
| 'use client'; | ||
|
|
||
| import { useTranslations } from 'next-intl'; | ||
| import { useTheme } from 'next-themes'; | ||
| import { usePending } from '@/components/auth/PendingBar'; | ||
| import { useAppForm } from '@/components/ui/Form'; | ||
| import { Link } from '@/components/ui/Link'; | ||
| import { api } from '@/lib/api/client'; | ||
| import type { TRPCClientError } from '@/lib/api/types'; | ||
| import { useRouter } from '@/lib/locale/navigation'; | ||
| import { forgotPasswordSchema } from '@/validations/auth/forgotPasswordSchema'; | ||
|
|
||
| function ForgotPasswordForm() { | ||
| const router = useRouter(); | ||
| const t = useTranslations('auth'); | ||
| const tUi = useTranslations('ui'); | ||
| const formSchema = forgotPasswordSchema(useTranslations()); | ||
| const { resolvedTheme } = useTheme(); | ||
| const { isPending, setPending } = usePending(); | ||
|
|
||
| const createRequestMutation = api.forgotPassword.createRequest.useMutation({ | ||
| onMutate: () => setPending(true), | ||
| onSettled: () => setPending(false), | ||
| onSuccess: (id) => | ||
| router.push({ | ||
| pathname: '/auth/forgot-password/[requestId]', | ||
| params: { requestId: id }, | ||
| }), | ||
| }); | ||
|
|
||
| const form = useAppForm({ | ||
| validators: { | ||
| onChange: formSchema, | ||
| onSubmitAsync: async ({ value }) => { | ||
| try { | ||
| await createRequestMutation.mutateAsync(value); | ||
| } catch (error: unknown) { | ||
ZeroWave022 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| setPending(false); | ||
| const TRPCError = error as TRPCClientError; | ||
| if (!TRPCError.data?.toast) { | ||
| return { fields: { email: { message: TRPCError.message } } }; | ||
| } | ||
| return ' '; | ||
| } | ||
| }, | ||
| }, | ||
| defaultValues: { | ||
| email: '', | ||
| theme: resolvedTheme as 'light' | 'dark', | ||
| }, | ||
| }); | ||
|
|
||
| return ( | ||
| <div | ||
| className={`flex h-full flex-col transition-opacity duration-500 ${isPending ? 'pointer-events-none opacity-50' : ''}`} | ||
| > | ||
| <div className='mb-4 space-y-2 text-center'> | ||
| <h1 className='text-4xl'>{t('forgotPassword')}</h1> | ||
| <p className='text-sm'>{t('forgotPasswordDescription')}</p> | ||
| </div> | ||
| <form | ||
| onSubmit={(e) => { | ||
| e.preventDefault(); | ||
| form.handleSubmit(); | ||
| }} | ||
| className='relative grow space-y-6' | ||
| > | ||
| <form.AppForm> | ||
| <form.AppField name='email'> | ||
| {(field) => ( | ||
| <field.TextField | ||
| label={t('form.email.label')} | ||
| placeholder='[email protected]' | ||
| autoComplete='email' | ||
| /> | ||
| )} | ||
| </form.AppField> | ||
| <div className='absolute bottom-0 flex w-full xs:flex-row-reverse flex-col justify-between gap-2'> | ||
| <form.SubmitButton>{t('submit')}</form.SubmitButton> | ||
| <Link | ||
| variant='secondary' | ||
| size='default' | ||
| href='/auth/account' | ||
| className='gap-2' | ||
| > | ||
| {tUi('goBack')} | ||
| </Link> | ||
| </div> | ||
| </form.AppForm> | ||
| </form> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| export { ForgotPasswordForm }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.