The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update password email
Steven Tey4d7e5843cf19
diff --git a/apps/web/app/api/auth/reset-password/route.ts b/apps/web/app/api/auth/reset-password/route.tsindex eac2fa1f63..7ed61e8730 100644--- a/apps/web/app/api/auth/reset-password/route.ts+++ b/apps/web/app/api/auth/reset-password/route.ts@@ -3,6 +3,7 @@ import { parseRequestBody, ratelimitOrThrow } from "@/lib/api/utils";import { hashPassword } from "@/lib/auth/password";import { prisma } from "@/lib/prisma";import { resetPasswordSchema } from "@/lib/zod/schemas/auth";+import { waitUntil } from "@vercel/functions";import { sendEmail } from "emails";import PasswordUpdated from "emails/password-updated";import { NextRequest, NextResponse } from "next/server";@@ -59,14 +60,17 @@ export async function POST(req: NextRequest) {}),]);- // Send the email to inform the user that their password has been updated- await sendEmail({- subject: `Your ${process.env.NEXT_PUBLIC_APP_NAME} account password has been reset`,- email: identifier,- react: PasswordUpdated({+ // Send the email to inform the user that their password has been reset+ waitUntil(+ sendEmail({+ subject: `Your ${process.env.NEXT_PUBLIC_APP_NAME} account password has been reset`,email: identifier,+ react: PasswordUpdated({+ email: identifier,+ verb: "reset",+ }),}),- });+ );return NextResponse.json({ ok: true });} catch (error) {diff --git a/apps/web/app/api/user/password/route.ts b/apps/web/app/api/user/password/route.tsindex 01b810a507..d2fbaa663e 100644--- a/apps/web/app/api/user/password/route.ts+++ b/apps/web/app/api/user/password/route.ts@@ -4,6 +4,9 @@ import { withSession } from "@/lib/auth";import { hashPassword, validatePassword } from "@/lib/auth/password";import { prisma } from "@/lib/prisma";import { updatePasswordSchema } from "@/lib/zod/schemas/auth";+import { waitUntil } from "@vercel/functions";+import { sendEmail } from "emails";+import PasswordUpdated from "emails/password-updated";import { NextResponse } from "next/server";// PATCH /api/user/password - updates the user's password@@ -49,8 +52,16 @@ export const PATCH = withSession(async ({ req, session }) => {},});- // TODO:- // Send an email to the user notifying them that their password has been updated+ // Send the email to inform the user that their password has been updated+ waitUntil(+ sendEmail({+ subject: `Your ${process.env.NEXT_PUBLIC_APP_NAME} account password has been updated`,+ email: session.user.email,+ react: PasswordUpdated({+ email: session.user.email,+ }),+ }),+ );return NextResponse.json({ ok: true });});diff --git a/apps/web/emails/password-updated.tsx b/apps/web/emails/password-updated.tsxindex 5c505e35f0..6ad361d819 100644--- a/apps/web/emails/password-updated.tsx+++ b/apps/web/emails/password-updated.tsx@@ -15,13 +15,15 @@ import Footer from "./components/footer";export default function PasswordUpdated({email = "[email protected]",+ verb = "updated",}: {email: string;+ verb?: "reset" | "updated";}) {return (<Html><Head />- <Preview>Your password has been reset</Preview>+ <Preview>Your password has been {verb}</Preview><Tailwind><Body className="mx-auto my-auto bg-white font-sans"><Container className="mx-auto my-10 max-w-[500px] rounded border border-solid border-gray-200 px-10 py-5">@@ -34,10 +36,10 @@ export default function PasswordUpdated({/></Section><Heading className="mx-0 my-7 p-0 text-center text-xl font-semibold text-black">- Password has been reset+ Password has been {verb}</Heading><Text className="text-sm leading-6 text-black">- The password for your Dub account has been successfully reset.+ The password for your Dub account has been successfully {verb}.</Text><Text className="text-sm leading-6 text-black">If you did not make this change or you believe an unauthorised