'use client'; import { useState } from 'react'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { authApi } from '@/lib/api'; import { BrandMark } from '@/components/BrandMark'; export default function LoginPage() { const router = useRouter(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(''); const [loading, setLoading] = useState(false); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(''); setLoading(true); try { const response = await authApi.login({ username: email, password }); localStorage.setItem('access_token', response.access_token); // Redirect to dashboard router.push('/dashboard'); } catch (err: unknown) { const error = err as { response?: { data?: { detail?: string } } }; setError(error.response?.data?.detail || 'Login failed. Please try again.'); } finally { setLoading(false); } }; const handleGoogleLogin = async () => { try { const redirectUri = `${window.location.origin}/auth/callback`; const authUrl = await authApi.getGoogleAuthUrl(redirectUri); window.location.href = authUrl; } catch { setError('Failed to initialize Google login'); } }; return (
Continue to your mailbox delivery dashboard.