From 8733795c8449f3514369d7b4220934760e386f1b Mon Sep 17 00:00:00 2001 From: Biswa Kalyan Bhuyan Date: Fri, 25 Apr 2025 01:09:30 +0530 Subject: finance/frontend: fix: did some minor changes to the frontend --- frontend/src/app/(auth)/login/page.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'frontend/src/app/(auth)/login/page.tsx') diff --git a/frontend/src/app/(auth)/login/page.tsx b/frontend/src/app/(auth)/login/page.tsx index 7460b8a..23cdd24 100644 --- a/frontend/src/app/(auth)/login/page.tsx +++ b/frontend/src/app/(auth)/login/page.tsx @@ -6,13 +6,14 @@ import Link from 'next/link'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; -import { authApi } from '@/lib/api'; +import { useAuth } from '@/components/shared/AuthContext'; import { useNotification } from '@/components/shared/NotificationContext'; export default function LoginPage() { const router = useRouter(); const searchParams = useSearchParams(); const { showNotification } = useNotification(); + const { login, isAuthenticated } = useAuth(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); @@ -23,7 +24,12 @@ export default function LoginPage() { if (searchParams.get('signup') === 'success') { showNotification('success', 'Account created successfully! Please log in.'); } - }, [searchParams, showNotification]); + + // Redirect if already authenticated + if (isAuthenticated) { + router.push('/dashboard'); + } + }, [searchParams, showNotification, isAuthenticated, router]); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); @@ -31,8 +37,8 @@ export default function LoginPage() { setIsLoading(true); try { - await authApi.login(email, password); - showNotification('success', 'Logged in successfully!'); + const response = await login(email, password); + showNotification('success', `Welcome back, ${response?.user?.Name || 'user'}! You've been successfully logged in.`); router.push('/dashboard'); } catch (err: any) { setError(err.message || 'Login failed'); -- cgit v1.2.3-59-g8ed1b