The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update forgot password
Kiran Kb4f12defd80c
diff --git a/apps/web/app/api/cron/disposable-emails/route.ts b/apps/web/app/api/cron/disposable-emails/route.tsindex c83b263044..2bf4ea5a14 100644--- a/apps/web/app/api/cron/disposable-emails/route.ts+++ b/apps/web/app/api/cron/disposable-emails/route.ts@@ -1,27 +1,24 @@import { handleAndReturnErrorResponse } from "@/lib/api/errors";-import { verifyQstashSignature } from "@/lib/cron/verify-qstash";import { verifyVercelSignature } from "@/lib/cron/verify-vercel";import { redis } from "@/lib/upstash";import { log } from "@dub/utils";import { NextResponse } from "next/server";-// Cron to update the disposable email domains list in Redis-// Runs every Monday at noon UTC (0 12 * * 1)-export const dynamic = "force-dynamic";-async function handler(req: Request) {+// Cron to update the disposable email domains list in Redis+// Runs every Monday at noon UTC (0 12 * * 1)+export async function GET(req: Request) {try {- if (req.method === "GET") await verifyVercelSignature(req);- else if (req.method === "POST") await verifyQstashSignature(req);+ await verifyVercelSignature(req);const disposableEmails = await fetch("https://raw.githubusercontent.com/disposable-email-domains/disposable-email-domains/master/disposable_email_blocklist.conf",);const domains = (await disposableEmails.text()).split("\n").filter(Boolean);+if (domains.length < 100) {- // There should definitely be at least 100 domains - something is wrongthrow new Error("Disposable email domains list is too short");}@@ -30,9 +27,7 @@ async function handler(req: Request) {await redis.sadd("disposableEmailDomainsTmp", ...domains);await redis.rename("disposableEmailDomainsTmp", "disposableEmailDomains");- return NextResponse.json({- response: "success",- });+ return NextResponse.json({ status: "OK" });} catch (error) {await log({message: `Error updating disposable email domains list: ${error.message}`,@@ -42,5 +37,3 @@ async function handler(req: Request) {return handleAndReturnErrorResponse(error);}}--export { handler as GET, handler as POST };diff --git a/apps/web/app/app.dub.co/(auth)/forgot-password/form.tsx b/apps/web/app/app.dub.co/(auth)/forgot-password/form.tsxindex 1e8f6b1dfb..60744f6052 100644--- a/apps/web/app/app.dub.co/(auth)/forgot-password/form.tsx+++ b/apps/web/app/app.dub.co/(auth)/forgot-password/form.tsx@@ -3,71 +3,75 @@import { requestPasswordResetAction } from "@/lib/actions/request-password-reset";import { Button, Input, useMediaQuery } from "@dub/ui";import { useAction } from "next-safe-action/hooks";+import Link from "next/link";import { useRouter, useSearchParams } from "next/navigation";import { useState } from "react";import { toast } from "sonner";-export function ForgotPasswordForm() {+export const ForgotPasswordForm = () => {const router = useRouter();const { isMobile } = useMediaQuery();const searchParams = useSearchParams();-const [email, setEmail] = useState(searchParams.get("email") || "");- const { executeAsync, result, status, isExecuting } = useAction(- requestPasswordResetAction,- {- onSuccess() {- toast.success("Reset instructions sent! Redirecting to login...");- router.push("/login");- },+ const { executeAsync, isExecuting } = useAction(requestPasswordResetAction, {+ onSuccess() {+ toast.success(+ "You will receive an email with instructions to reset your password.",+ );+ router.push("/login");},- );+ onError({ error }) {+ toast.error(error.serverError?.serverError);+ },+ });return (<>- {result.serverError && (- <div className="rounded-md bg-red-100 p-3 text-red-900 dark:bg-red-900 dark:text-red-200">- <div className="relative flex md:flex-row">- <div className="flex flex-grow flex-col sm:flex-row">- <div className="ltr:ml-3 rtl:mr-3">- <h3 className="text-sm font-medium">- {result.serverError.serverError}- </h3>- </div>- </div>- </div>+ <div className="w-full max-w-md overflow-hidden border-y border-gray-200 sm:rounded-2xl sm:border sm:shadow-sm">+ <div className="flex flex-col items-center justify-center space-y-3 border-b border-gray-200 bg-white px-4 py-6 pt-8 text-center sm:px-16">+ <h3 className="text-xl font-semibold">Reset your password</h3></div>- )}- <form- onSubmit={async (e) => {- e.preventDefault();- await executeAsync({ email });- }}- >- <div className="flex flex-col gap-8">- <label>- <span className="text-sm font-medium text-gray-700">- Email Address- </span>- <Input- type="email"- autoFocus={!isMobile}- value={email}- placeholder="[email protected]"- onChange={(e) => setEmail(e.target.value)}- className="mt-1"- />- </label>- <Button- text={status === "executing" ? "Sending..." : "Send Reset Link"}- type="submit"- loading={isExecuting}- disabled={email.length < 3}- />+ <div className="grid gap-3 bg-gray-50 px-4 py-8 sm:px-16">+ <form+ onSubmit={(e) => {+ e.preventDefault();+ executeAsync({ email });+ }}+ >+ <div className="flex flex-col gap-8">+ <label>+ <span className="text-sm font-medium text-gray-700">Email</span>+ <Input+ type="email"+ autoFocus={!isMobile}+ value={email}+ placeholder="[email protected]"+ onChange={(e) => setEmail(e.target.value)}+ className="mt-1"+ />+ </label>+ <Button+ type="submit"+ text={isExecuting ? "Sending..." : "Send reset link"}+ loading={isExecuting}+ disabled={email.length < 3}+ />+ </div>+ </form></div>- </form>+ </div>++ <p className="mt-4 text-center text-sm text-gray-500">+ Already have an account? + <Link+ href="/login"+ className="font-semibold text-gray-500 underline underline-offset-2 transition-colors hover:text-black"+ >+ Sign in+ </Link>+ </p></>);-}+};diff --git a/apps/web/app/app.dub.co/(auth)/forgot-password/page.tsx b/apps/web/app/app.dub.co/(auth)/forgot-password/page.tsxindex 1e47cf8b40..6c0dbfb83f 100644--- a/apps/web/app/app.dub.co/(auth)/forgot-password/page.tsx+++ b/apps/web/app/app.dub.co/(auth)/forgot-password/page.tsx@@ -1,4 +1,4 @@-import AuthLayout from "@/ui/layout/old-auth-layout";+import { AuthLayout } from "@/ui/layout/auth-layout";import { constructMetadata } from "@dub/utils";import { ForgotPasswordForm } from "./form";@@ -8,7 +8,7 @@ export const metadata = constructMetadata({export default function ForgotPasswordPage() {return (- <AuthLayout variant="login" heading="Reset your Dub password">+ <AuthLayout><ForgotPasswordForm /></AuthLayout>);diff --git a/apps/web/lib/actions/create-user-account.ts b/apps/web/lib/actions/create-user-account.tsindex 75bec00851..4135b3dd26 100644--- a/apps/web/lib/actions/create-user-account.ts+++ b/apps/web/lib/actions/create-user-account.ts@@ -24,8 +24,6 @@ export const createUserAccountAction = actionClient.action(async ({ parsedInput }) => {const { email, password, code } = parsedInput;- console.log("createUserAccountAction", { email, password, code });-const { success } = await ratelimit(2, "1 m").limit(`signup:${getIP()}`);if (!success) {diff --git a/apps/web/lib/actions/request-password-reset.ts b/apps/web/lib/actions/request-password-reset.tsindex f52fb73410..c6fe47b648 100644--- a/apps/web/lib/actions/request-password-reset.ts+++ b/apps/web/lib/actions/request-password-reset.ts@@ -29,7 +29,6 @@ export const requestPasswordResetAction = actionClientthrow new Error("Too many requests. Please try again later.");}- // Check user with email existsconst user = await prisma.user.findUnique({where: {email,@@ -37,7 +36,7 @@ export const requestPasswordResetAction = actionClient});if (!user) {- throw new Error("An user with this email does not exist.");+ return { ok: true };}const token = randomBytes(32).toString("hex");@@ -58,6 +57,10 @@ export const requestPasswordResetAction = actionClient}),]);+ console.log({+ url: `${process.env.NEXTAUTH_URL}/auth/reset-password/${token}`,+ });+await sendEmail({subject: `${process.env.NEXT_PUBLIC_APP_NAME}: Password reset instructions`,email,