Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Reset password WIP

Tim Wilsond9be10cc1bf2
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.tsx
new file mode 100644
index 0000000000..ec0f992982
--- /dev/null
+++ b/apps/web/app/app.dub.co/(auth)/forgot-password/form.tsx
@@ -0,0 +1,67 @@
+"use client";
+
+import { verifyEmailAction } from "@/lib/actions/verify-email";
+import { Button, Input, useMediaQuery } from "@dub/ui";
+import { useAction } from "next-safe-action/hooks";
+import { useRouter, useSearchParams } from "next/navigation";
+import { useState } from "react";
+import { toast } from "sonner";
+
+export function ForgotPasswordForm() {
+ const router = useRouter();
+ const { isMobile } = useMediaQuery();
+ const searchParams = useSearchParams();
+
+ const [email, setEmail] = useState(searchParams.get("email") || "");
+
+ const { executeAsync, result, status, isExecuting } = useAction(
+ verifyEmailAction,
+ {
+ onSuccess() {
+ toast.success("Email verified! Redirecting to login...");
+ router.push("/login");
+ },
+ },
+ );
+
+ 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>
+ )}
+
+ <form
+ onSubmit={async (e) => {
+ e.preventDefault();
+ //await executeAsync({ email, code });
+ }}
+ >
+ <div className="flex flex-col gap-8">
+ <Input
+ type="email"
+ autoFocus={!isMobile}
+ value={email}
+ placeholder="[email protected]"
+ onChange={(e) => setEmail(e.target.value)}
+ />
+ <Button
+ text={status === "executing" ? "Sending..." : "Send Reset Link"}
+ type="submit"
+ loading={isExecuting}
+ disabled={email.length < 3}
+ />
+ </div>
+ </form>
+ </>
+ );
+}
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.tsx
new file mode 100644
index 0000000000..7bf903f162
--- /dev/null
+++ b/apps/web/app/app.dub.co/(auth)/forgot-password/page.tsx
@@ -0,0 +1,15 @@
+import AuthLayout from "@/ui/layout/auth-layout";
+import { constructMetadata } from "@dub/utils";
+import { ForgotPasswordForm } from "./form";
+
+export const metadata = constructMetadata({
+ title: `Forgot Password for ${process.env.NEXT_PUBLIC_APP_NAME}`,
+});
+
+export default function ForgotPasswordPage() {
+ return (
+ <AuthLayout variant="login" heading="Reset your Dub password">
+ <ForgotPasswordForm />
+ </AuthLayout>
+ );
+}
diff --git a/apps/web/app/app.dub.co/(auth)/login/form.tsx b/apps/web/app/app.dub.co/(auth)/login/form.tsx
index 030de64088..b97de3b701 100644
--- a/apps/web/app/app.dub.co/(auth)/login/form.tsx
+++ b/apps/web/app/app.dub.co/(auth)/login/form.tsx
@@ -15,6 +15,7 @@ import { InputPassword } from "@dub/ui/src/icons";
import { cn } from "@dub/utils";
import { Lock, Mail } from "lucide-react";
import { signIn } from "next-auth/react";
+import Link from "next/link";
import { useRouter, useSearchParams } from "next/navigation";
import {
Dispatch,
@@ -255,6 +256,14 @@ export default function LoginForm() {
</span>
</div>
)}
+ {showPasswordField && (
+ <Link
+ href="/forgot-password"
+ className="text-center text-xs text-gray-500 transition-colors hover:text-black"
+ >
+ Forgot password?
+ </Link>
+ )}
<div className="my-2 flex flex-shrink items-center justify-center gap-2">
<div className="grow basis-0 border-b border-gray-300" />
<span className="text-xs font-normal uppercase leading-none text-gray-500">
@@ -391,7 +400,7 @@ const SignInWithEmail = () => {
}
});
}}
- className="flex flex-col space-y-3"
+ className="flex flex-col gap-y-3"
>
{authMethod === "email" && (
<input
diff --git a/apps/web/app/app.dub.co/(auth)/register/verify-email/form.tsx b/apps/web/app/app.dub.co/(auth)/register/verify-email/form.tsx
index 95e992ae78..230be4b10f 100644
--- a/apps/web/app/app.dub.co/(auth)/register/verify-email/form.tsx
+++ b/apps/web/app/app.dub.co/(auth)/register/verify-email/form.tsx
@@ -1,7 +1,7 @@
"use client";
import { verifyEmailAction } from "@/lib/actions/verify-email";
-import { Button } from "@dub/ui";
+import { Button, useMediaQuery } from "@dub/ui";
import { cn } from "@dub/utils";
import { OTPInput } from "input-otp";
import { useAction } from "next-safe-action/hooks";
@@ -11,6 +11,7 @@ import { toast } from "sonner";
export default function VerifyEmailForm() {
const router = useRouter();
+ const { isMobile } = useMediaQuery();
const [code, setCode] = useState("");
const searchParams = useSearchParams();
@@ -58,7 +59,7 @@ export default function VerifyEmailForm() {
maxLength={6}
value={code}
onChange={setCode}
- autoFocus
+ autoFocus={!isMobile}
containerClassName="group flex items-center justify-center"
render={({ slots }) => (
<div className="flex items-center">
diff --git a/apps/web/lib/middleware/app.ts b/apps/web/lib/middleware/app.ts
index 460818e7da..2fa4b55d57 100644
--- a/apps/web/lib/middleware/app.ts
+++ b/apps/web/lib/middleware/app.ts
@@ -13,6 +13,7 @@ export default async function AppMiddleware(req: NextRequest) {
if (
!user &&
path !== "/login" &&
+ path !== "/forgot-password" &&
path !== "/register" &&
path !== "/register/verify-email" &&
path !== "/auth/saml" &&
diff --git a/apps/web/ui/layout/auth-layout.tsx b/apps/web/ui/layout/auth-layout.tsx
index 312a08233e..f23b2b5c88 100644
--- a/apps/web/ui/layout/auth-layout.tsx
+++ b/apps/web/ui/layout/auth-layout.tsx
@@ -19,9 +19,11 @@ const logos = [
export default function AuthLayout({
variant,
+ heading,
children,
}: {
variant: "login" | "register";
+ heading?: string;
children: React.ReactNode;
}) {
return (
@@ -34,9 +36,10 @@ export default function AuthLayout({
<div className="w-full max-w-md overflow-hidden border-y border-gray-200 sm:rounded-2xl sm:border sm:shadow-sm">
<div className="border-b border-gray-200 bg-white pb-6 pt-8 text-center">
<h3 className="text-lg font-semibold">
- {variant === "login"
- ? "Sign in to your Dub account"
- : "Get started with Dub"}
+ {heading ||
+ (variant === "login"
+ ? "Sign in to your Dub account"
+ : "Get started with Dub")}
</h3>
</div>
<div className="grid gap-3 bg-gray-50 px-4 py-8 sm:px-16">