The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add reset login attempts in admin
Steven Tey9392952473fc
diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/reset-login-attempts.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/reset-login-attempts.tsxnew file mode 100644index 0000000000..8bae0dce68--- /dev/null+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/components/reset-login-attempts.tsx@@ -0,0 +1,59 @@+"use client";++import { LoadingSpinner } from "@dub/ui";+import { cn } from "@dub/utils";+import { useFormStatus } from "react-dom";+import { toast } from "sonner";++export function ResetLoginAttempts() {+ return (+ <div className="flex flex-col space-y-5">+ <form+ action={async (data) =>+ await fetch("/api/admin/reset-login-attempts", {+ method: "POST",+ body: JSON.stringify({+ email: data.get("email"),+ }),+ })+ .then((res) => res.json())+ .then((res) => {+ if (res.error) {+ toast.error(res.error);+ } else {+ toast.success("Login attempts have been reset");+ }+ })+ }+ >+ <Form />+ </form>+ </div>+ );+}++const Form = () => {+ const { pending } = useFormStatus();++ return (+ <div className="relative flex w-full rounded-md shadow-sm">+ <input+ name="email"+ id="email"+ type="email"+ required+ disabled={pending}+ autoComplete="off"+ className={cn(+ "block w-full rounded-md border-neutral-300 text-neutral-900 placeholder-neutral-400 focus:border-neutral-500 focus:outline-none focus:ring-neutral-500 sm:text-sm",+ pending && "bg-neutral-100",+ )}+ placeholder="[email protected]"+ aria-invalid="true"+ />+ {pending && (+ <LoadingSpinner className="absolute inset-y-0 right-2 my-auto h-full w-5 text-neutral-400" />+ )}+ </div>+ );+};diff --git a/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsx b/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsxindex 3ae6443cb1..be2f038f8d 100644--- a/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsx+++ b/apps/web/app/(ee)/admin.dub.co/(dashboard)/page.tsx@@ -4,6 +4,7 @@ import { DeletePartnerAccount } from "./components/delete-partner-account";import { ImpersonateUser } from "./components/impersonate-user";import { ImpersonateWorkspace } from "./components/impersonate-workspace";import { RefreshDomain } from "./components/refresh-domain";+import { ResetLoginAttempts } from "./components/reset-login-attempts";export const metadata = constructMetadata({title: "Dub Admin",@@ -51,6 +52,13 @@ export default function AdminPage() {</p><RefreshDomain /></div>+ <div className="flex flex-col space-y-4 px-5 py-10">+ <h2 className="text-xl font-semibold">Reset Login Attempts</h2>+ <p className="text-sm text-neutral-500">+ Reset a user's invalidLoginAttempts and lockedAt fields+ </p>+ <ResetLoginAttempts />+ </div></div>);}diff --git a/apps/web/app/(ee)/api/admin/reset-login-attempts/route.ts b/apps/web/app/(ee)/api/admin/reset-login-attempts/route.tsnew file mode 100644index 0000000000..aec41eecbf--- /dev/null+++ b/apps/web/app/(ee)/api/admin/reset-login-attempts/route.ts@@ -0,0 +1,48 @@+import { withAdmin } from "@/lib/auth";+import { prisma } from "@dub/prisma";+import { NextResponse } from "next/server";++// POST /api/admin/reset-login-attempts+export const POST = withAdmin(async ({ req }) => {+ const { email } = await req.json();++ if (!email) {+ return NextResponse.json(+ { error: "Email is required" },+ { status: 400 },+ );+ }++ const user = await prisma.user.findUnique({+ where: { email },+ select: {+ id: true,+ email: true,+ invalidLoginAttempts: true,+ lockedAt: true,+ },+ });++ if (!user) {+ return NextResponse.json({ error: "User not found" }, { status: 404 });+ }++ const updatedUser = await prisma.user.update({+ where: { email },+ data: {+ invalidLoginAttempts: 0,+ lockedAt: null,+ },+ select: {+ id: true,+ email: true,+ invalidLoginAttempts: true,+ lockedAt: true,+ },+ });++ return NextResponse.json({+ success: true,+ user: updatedUser,+ });+});