import { useState, useEffect } from 'react'; import { GithubOutlined } from '@ant-design/icons'; import { useNavigate, Link } from 'react-router'; import { toast } from 'sonner'; import { Icon } from '@iconify/react'; import { useAuthStore } from '../../features/auth/store/auth.store'; export default function LoginPage() { const navigate = useNavigate(); const login = useAuthStore((state) => state.login); const isAuthenticated = useAuthStore((state) => state.isAuthenticated); const [isGithubLoading, setIsGithubLoading] = useState(false); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(null); const [showPassword, setShowPassword] = useState(false); const [isSubmitting, setIsSubmitting] = useState(false); useEffect(() => { if (isAuthenticated) { navigate('/'); } }, [isAuthenticated, navigate]); useEffect(() => { const hashParams = new URLSearchParams(globalThis.location.hash.substring(1)); const urlParams = new URLSearchParams(globalThis.location.search); const accessToken = hashParams.get('access_token') || urlParams.get('access_token'); const type = hashParams.get('type') || urlParams.get('type'); if (accessToken) { if (type === 'recovery' || type === 'magiclink' || !type) { toast.info('Redirecting to password reset...'); navigate('/auth/reset-password?access_token=' + accessToken); } } }, [navigate]); const handleEmailLogin = async (e: React.FormEvent) => { e.preventDefault(); setError(null); if (!email || !password) { setError('Please enter both email and password'); return; } setIsSubmitting(true); try { const success = await login(email, password); if (success) { toast.success('Login successful!'); navigate('/'); } else { setError('Login failed. Please check your credentials.'); } } catch (err) { setError('Login failed. Please try again.'); } finally { setIsSubmitting(false); } }; const handleGithubLogin = async () => { toast.info('GitHub login coming soon'); }; return (

Welcome Back

Sign in to QR Campaign Manager

{error && (

{error}

)}
setEmail(e.target.value)} placeholder="your@email.com" disabled={isSubmitting} className="w-full px-4 py-2.5 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent bg-white text-gray-900 placeholder:text-gray-400 disabled:bg-gray-100 disabled:cursor-not-allowed" required />
Forgot password?
setPassword(e.target.value)} placeholder="••••••••" disabled={isSubmitting} className="w-full px-4 py-2.5 pr-12 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary-500 focus:border-transparent bg-white text-gray-900 placeholder:text-gray-400 disabled:bg-gray-100 disabled:cursor-not-allowed" required />
OR

Make sure your GitHub email is{' '} set to public {' '} for GitHub sign in to work.

Don't have an account?{' '} Sign up

By signing in, you agree to our Terms of Service and Privacy Policy

); }