From 0e10e62bfa1f9eb23f7ba84c632f15d9a2fe63a0 Mon Sep 17 00:00:00 2001
From: Krzysztof Czerwinski <34861343+kcze@users.noreply.github.com>
Date: Tue, 17 Dec 2024 18:30:18 +0000
Subject: [PATCH] feat(frontend): Reset password page (#8987)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Currently, users have no way to reset their password.
### Changes 🏗️
Add `reset_password` page that displays either form to send reset
password email or lets logged in user change their password. Login page
now shows clickable "Forgot your password?" link. After updating
password user is logged out and redirected to login page.
Note: Link provided in the email just logs user in and redirects to
reset password form but password update isn't enforced.
### Checklist 📋
#### For code changes:
- [x] I have clearly listed my changes in the PR description
- [x] I have made a test plan
- [x] I have tested my changes according to the test plan:
- [x] Email is sent
- [x] Link in the email logs user in and redirects to reset password
form
- [x] Reset password form works
Example test plan
- [ ] Create from scratch and execute an agent with at least 3 blocks
- [ ] Import an agent from file upload, and confirm it executes
correctly
- [ ] Upload agent to marketplace
- [ ] Import an agent from marketplace and confirm it executes correctly
- [ ] Edit an agent from monitor, and confirm it executes correctly
Examples of configuration changes
- Changing ports
- Adding new services that need to communicate with each other
- Secrets or environment variable changes
- New or infrastructure changes such as databases
{feedback}
+ + Forgot your password? + ); diff --git a/autogpt_platform/frontend/src/app/reset_password/page.tsx b/autogpt_platform/frontend/src/app/reset_password/page.tsx new file mode 100644 index 000000000..45a17cb49 --- /dev/null +++ b/autogpt_platform/frontend/src/app/reset_password/page.tsx @@ -0,0 +1,216 @@ +"use client"; +import { useSupabase } from "@/components/providers/SupabaseProvider"; +import { Button } from "@/components/ui/button"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; +import useUser from "@/hooks/useUser"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useRouter } from "next/navigation"; +import { useState } from "react"; +import { useForm } from "react-hook-form"; +import { FaSpinner } from "react-icons/fa"; +import { z } from "zod"; + +const emailFormSchema = z.object({ + email: z.string().email().min(2).max(64), +}); + +const resetPasswordFormSchema = z + .object({ + password: z.string().min(6).max(64), + confirmPassword: z.string().min(6).max(64), + }) + .refine((data) => data.password === data.confirmPassword, { + message: "Passwords don't match", + path: ["confirmPassword"], + }); + +export default function ResetPasswordPage() { + const { supabase, isLoading: isSupabaseLoading } = useSupabase(); + const { user, isLoading: isUserLoading } = useUser(); + const router = useRouter(); + const [isLoading, setIsLoading] = useState(false); + const [feedback, setFeedback] = useState