From 9a179d136ef8ed6584a37e6e030e3e3dbb4e17bf Mon Sep 17 00:00:00 2001
From: "gpt-engineer-app[bot]"
<159125892+gpt-engineer-app[bot]@users.noreply.github.com>
Date: Wed, 2 Jul 2025 18:29:30 +0000
Subject: [PATCH] Fix: Redirect to dashboard after login
- Redirect to dashboard after successful login.
- Created `/auth/reset` page for password reset functionality.
---
src/App.tsx | 3 +
src/components/auth/ForgotPasswordForm.tsx | 2 +-
src/components/auth/LoginForm.tsx | 2 +-
src/pages/AuthReset.tsx | 139 +++++++++++++++++++++
4 files changed, 144 insertions(+), 2 deletions(-)
create mode 100644 src/pages/AuthReset.tsx
diff --git a/src/App.tsx b/src/App.tsx
index be2abfb..ec0e075 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,3 +1,4 @@
+
import { Toaster } from "@/components/ui/sonner";
import { TooltipProvider } from "@/components/ui/tooltip";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
@@ -8,6 +9,7 @@ import { useAuthStore } from "@/stores/authStore";
import ProtectedRoute from "@/components/auth/ProtectedRoute";
import Layout from "@/components/layout/Layout";
import ResetPassword from '@/pages/ResetPassword';
+import AuthReset from '@/pages/AuthReset';
// Pages
import Index from "./pages/Index";
@@ -60,6 +62,7 @@ function App() {
{/* Rotas públicas */}
} />
} />
+ } />
} />
} />
diff --git a/src/components/auth/ForgotPasswordForm.tsx b/src/components/auth/ForgotPasswordForm.tsx
index b6095a1..57ef920 100644
--- a/src/components/auth/ForgotPasswordForm.tsx
+++ b/src/components/auth/ForgotPasswordForm.tsx
@@ -25,7 +25,7 @@ const ForgotPasswordForm = ({ onBackToLogin }: ForgotPasswordFormProps) => {
try {
const { error } = await supabase.auth.resetPasswordForEmail(email, {
- redirectTo: `${window.location.origin}/reset-password`,
+ redirectTo: `${window.location.origin}/auth/reset`,
});
if (error) {
diff --git a/src/components/auth/LoginForm.tsx b/src/components/auth/LoginForm.tsx
index 44589b1..e08d408 100644
--- a/src/components/auth/LoginForm.tsx
+++ b/src/components/auth/LoginForm.tsx
@@ -53,7 +53,7 @@ const LoginForm = ({ isLoading, setIsLoading, onForgotPassword }: LoginFormProps
});
// Redirecionar para dashboard
- navigate('/');
+ navigate('/dashboard');
}
} catch (error) {
console.error('Erro inesperado no login:', error);
diff --git a/src/pages/AuthReset.tsx b/src/pages/AuthReset.tsx
new file mode 100644
index 0000000..cb4c02c
--- /dev/null
+++ b/src/pages/AuthReset.tsx
@@ -0,0 +1,139 @@
+
+import { useState, useEffect } from 'react';
+import { useNavigate, useSearchParams } 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 { Lock } from "lucide-react";
+import { supabase } from '@/integrations/supabase/client';
+import { toast } from "sonner";
+
+const AuthReset = () => {
+ const navigate = useNavigate();
+ const [searchParams] = useSearchParams();
+ const [novaSenha, setNovaSenha] = useState('');
+ const [isLoading, setIsLoading] = useState(false);
+ const [error, setError] = useState('');
+ const [tokenValido, setTokenValido] = useState(true);
+
+ useEffect(() => {
+ const accessToken = searchParams.get('access_token');
+
+ if (!accessToken) {
+ setTokenValido(false);
+ setError('Token de redefinição inválido ou ausente.');
+ }
+ }, [searchParams]);
+
+ const handleSubmit = async (e: React.FormEvent) => {
+ e.preventDefault();
+ setIsLoading(true);
+ setError('');
+
+ if (!novaSenha) {
+ setError('Por favor, digite uma nova senha.');
+ setIsLoading(false);
+ return;
+ }
+
+ if (novaSenha.length < 6) {
+ setError('A senha deve ter pelo menos 6 caracteres.');
+ setIsLoading(false);
+ return;
+ }
+
+ try {
+ const { error } = await supabase.auth.updateUser({
+ password: novaSenha
+ });
+
+ if (error) {
+ setError('Erro ao redefinir a senha: ' + error.message);
+ } else {
+ toast.success('Senha redefinida com sucesso!');
+ navigate('/auth');
+ }
+ } catch (error) {
+ setError('Erro inesperado. Tente novamente.');
+ } finally {
+ setIsLoading(false);
+ }
+ };
+
+ if (!tokenValido) {
+ return (
+
+
+
+ Erro
+
+ Token de redefinição inválido ou ausente.
+
+
+
+
+
+
+
+ );
+ }
+
+ return (
+
+
+
+
+
+
+ Redefinição de senha
+
+ Digite sua nova senha
+
+
+
+
+
+
+
+ );
+};
+
+export default AuthReset;