-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
1,028 additions
and
54 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 |
---|---|---|
|
@@ -19,4 +19,11 @@ REDIS_USERNAME= | |
REDIS_PASSWORD= | ||
REDIS_PORT=6379 | ||
REDIS_URL=redis://localhost:6379 | ||
REDIS_USE_TLS=false | ||
REDIS_USE_TLS=false | ||
SMTP_HOST=youtSmptHost | ||
SMTP_PORT=465 | ||
SMTP_USERNAME=secret | ||
SMTP_PASSWORD=secret | ||
SMTP_FROM_NAME=FromName | ||
SMTP_FROM_EMAIL=[email protected] | ||
SUPPORT_EMAIL=[email protected] |
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 |
---|---|---|
|
@@ -13,4 +13,4 @@ | |
"components": "@/components", | ||
"utils": "@/lib/utils" | ||
} | ||
} | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
15 changes: 15 additions & 0 deletions
15
prisma/migrations/20230914080302_add_reset_password/migration.sql
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,15 @@ | ||
-- CreateTable | ||
CREATE TABLE "ResetPassordToken" ( | ||
"identifier" TEXT NOT NULL, | ||
"token" TEXT NOT NULL, | ||
"expires" TIMESTAMP(3) NOT NULL | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "ResetPassordToken_identifier_key" ON "ResetPassordToken"("identifier"); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "ResetPassordToken_token_key" ON "ResetPassordToken"("token"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "ResetPassordToken" ADD CONSTRAINT "ResetPassordToken_identifier_fkey" FOREIGN KEY ("identifier") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20230914084608_created_ad_on_reset_password/migration.sql
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,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "ResetPassordToken" ADD COLUMN "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
"use client" | ||
|
||
import { zodResolver } from "@hookform/resolvers/zod" | ||
import { Clock } from "lucide-react" | ||
import { useRouter } from "next/navigation" | ||
import { useState } from "react" | ||
import { useForm } from "react-hook-form" | ||
import { z } from "zod" | ||
import AutoRefresh from "@/components/auto-refresh" | ||
import { Button } from "@/components/ui/button" | ||
import { Form } from "@/components/ui/form" | ||
import FormField from "@/components/ui/form-field" | ||
import { Label } from "@/components/ui/label" | ||
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip" | ||
import { toast } from "@/components/ui/use-toast" | ||
import { TDictionary } from "@/lib/langs" | ||
import { forgotPasswordSchema } from "@/lib/schemas/user" | ||
import { trpc } from "@/lib/trpc/client" | ||
import { handleMutationError } from "@/lib/utils/client-utils" | ||
import { resendResetPasswordExpiration } from "@/types/constants" | ||
|
||
const formSchema = forgotPasswordSchema | ||
type IForm = z.infer<ReturnType<typeof formSchema>> | ||
|
||
export default function ForgotPasswordForm({ dictionary }: { dictionary: TDictionary }) { | ||
const router = useRouter() | ||
|
||
const [latestEmailSentAt, setLatestEmailSentAt] = useState<number | null>(null) | ||
|
||
const forgotPasswordMutation = trpc.me.forgotPassword.useMutation({ | ||
onError: (error) => handleMutationError(error, dictionary, router), | ||
onSuccess: () => { | ||
setLatestEmailSentAt(Date.now()) | ||
toast({ | ||
title: dictionary.forgotPasswordSuccessTitle, | ||
description: dictionary.forgotPasswordSuccessDescription, | ||
}) | ||
}, | ||
}) | ||
|
||
const form = useForm<IForm>({ | ||
resolver: zodResolver(formSchema(dictionary)), | ||
defaultValues: { | ||
email: "", | ||
}, | ||
}) | ||
|
||
async function onSubmit(data: IForm) { | ||
forgotPasswordMutation.mutate(data) | ||
} | ||
|
||
const isLoading = forgotPasswordMutation.isLoading | ||
const retryIn = () => | ||
latestEmailSentAt ? new Date(resendResetPasswordExpiration - (Date.now() - latestEmailSentAt)) : null | ||
const retryInValue = retryIn() | ||
const isDisabled = isLoading || (latestEmailSentAt && retryInValue ? retryInValue.getTime() > 0 : false) | ||
|
||
return ( | ||
<Form {...form}> | ||
<form onSubmit={form.handleSubmit(onSubmit)} className={"relative !mt-5 grid w-[350px] space-y-2"}> | ||
<div className="grid gap-1"> | ||
<Label className="sr-only" htmlFor="email"> | ||
{dictionary.email} | ||
</Label> | ||
<FormField | ||
placeholder={dictionary.emailPlaceholder} | ||
type="email" | ||
autoCapitalize="none" | ||
autoComplete="email" | ||
autoCorrect="off" | ||
disabled={isDisabled} | ||
form={form} | ||
name="email" | ||
/> | ||
</div> | ||
<Button type="submit" isLoading={isLoading} disabled={isDisabled}> | ||
{dictionary.send} | ||
</Button> | ||
{latestEmailSentAt !== null && ( | ||
<TooltipProvider> | ||
<Tooltip> | ||
<TooltipTrigger className="absolute -bottom-1 right-0 ml-auto flex w-max translate-y-full" type="button"> | ||
<AutoRefresh | ||
callback={() => { | ||
const retryInValue = retryIn() | ||
const retryInFormatted = | ||
retryInValue && retryInValue.getTime() > 0 | ||
? `${Math.floor(retryInValue.getTime() / 1000 / 60)}:${ | ||
Math.floor(retryInValue.getTime() / 1000) % 60 | ||
}` | ||
: null | ||
return ( | ||
<div className="ml-auto flex flex-row items-center text-sm text-gray-500"> | ||
<Clock className="mr-1 inline-block h-4 w-4" /> | ||
{retryInFormatted} | ||
</div> | ||
) | ||
}} | ||
interval={1000} | ||
/> | ||
</TooltipTrigger> | ||
<TooltipContent> | ||
<p>{dictionary.timeUntilYouCanRequestAnotherEmail}</p> | ||
</TooltipContent> | ||
</Tooltip> | ||
</TooltipProvider> | ||
)} | ||
</form> | ||
</Form> | ||
) | ||
} |
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,21 @@ | ||
import { getDictionary } from "@/lib/langs" | ||
import { Locale } from "i18n-config" | ||
import ForgotPasswordForm from "./form" | ||
|
||
export default async function ForgotPassword({ | ||
params: { lang }, | ||
}: { | ||
params: { | ||
lang: Locale | ||
} | ||
}) { | ||
const dictionary = await getDictionary(lang) | ||
|
||
return ( | ||
<main className="container flex flex-1 flex-col items-center justify-center space-y-2"> | ||
<h1 className="text-2xl font-semibold tracking-tight">{dictionary.forgotPasswordTitle}</h1> | ||
<p className="text-sm text-muted-foreground">{dictionary.forgotPasswordDescription}</p> | ||
<ForgotPasswordForm dictionary={dictionary} /> | ||
</main> | ||
) | ||
} |
Oops, something went wrong.