@@ -66,7 +96,11 @@ const Auth = () => {
-
+
diff --git a/src/pages/ResetPassword.tsx b/src/pages/ResetPassword.tsx
new file mode 100644
index 0000000..c3c568f
--- /dev/null
+++ b/src/pages/ResetPassword.tsx
@@ -0,0 +1,147 @@
+
+import { useState, useEffect } from 'react';
+import { useNavigate } from 'react-router-dom';
+import { Button } from "@/components/ui/button";
+import { Input } from "@/components/ui/input";
+import { Label } from "@/components/ui/label";
+import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
+import { Alert, AlertDescription } from "@/components/ui/alert";
+import { CheckCircle2, Lock } from "lucide-react";
+import { supabase } from '@/integrations/supabase/client';
+import { toast } from "sonner";
+
+const ResetPassword = () => {
+ const navigate = useNavigate();
+ const [password, setPassword] = useState('');
+ const [confirmPassword, setConfirmPassword] = useState('');
+ const [isLoading, setIsLoading] = useState(false);
+ const [error, setError] = useState('');
+ const [success, setSuccess] = useState(false);
+
+ useEffect(() => {
+ // Verificar se há um token de recuperação na URL
+ const hashParams = new URLSearchParams(window.location.hash.substring(1));
+ const accessToken = hashParams.get('access_token');
+ const refreshToken = hashParams.get('refresh_token');
+
+ if (!accessToken || !refreshToken) {
+ toast.error("Link inválido ou expirado");
+ navigate('/auth');
+ }
+ }, [navigate]);
+
+ const handleSubmit = async (e: React.FormEvent) => {
+ e.preventDefault();
+ setIsLoading(true);
+ setError('');
+
+ if (password !== confirmPassword) {
+ setError('As senhas não coincidem');
+ setIsLoading(false);
+ return;
+ }
+
+ if (password.length < 6) {
+ setError('A senha deve ter pelo menos 6 caracteres');
+ setIsLoading(false);
+ return;
+ }
+
+ try {
+ const { error } = await supabase.auth.updateUser({
+ password: password
+ });
+
+ if (error) {
+ setError(error.message);
+ } else {
+ setSuccess(true);
+ toast.success("Senha redefinida com sucesso!");
+ setTimeout(() => {
+ navigate('/auth');
+ }, 3000);
+ }
+ } catch (error) {
+ setError('Erro inesperado. Tente novamente.');
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
+ if (success) {
+ return (
+
+
+
+
+
+
+ Senha redefinida!
+
+ Sua senha foi alterada com sucesso. Você será redirecionado para o login.
+
+
+
+
+ );
+ }
+
+ return (
+
+
+
+
+
+
+ Nova senha
+
+ Digite sua nova senha
+
+
+
+
+
+
+
+ );
+};
+
+export default ResetPassword;