import { useState, useEffect } from 'react'; import { useGitHubAuth, useLogin, } from '@imphnen-frontend-service/service'; import { GithubOutlined } from '@ant-design/icons'; import { useNavigate, Link } from 'react-router'; import { toast } from 'sonner'; import { Icon } from '@iconify/react'; import { ThemeToggle } from '../../../components/theme-toggle'; export default function LoginPage() { const navigate = useNavigate(); const { signInWithGitHub } = useGitHubAuth(); const loginMutation = useLogin(); const [isGithubLoading, setIsGithubLoading] = useState(false); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [error, setError] = useState(null); const [showPassword, setShowPassword] = useState(false); // Check for password reset tokens in URL and redirect to reset-password page 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 we have an access_token, this is likely a password reset redirect that landed on the wrong page if (accessToken) { console.log('[Login] Detected access_token, redirecting to reset-password page'); // Check if it's a password recovery 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; } try { const result = await loginMutation.mutateAsync({ email, password }); toast.success('Login successful!'); // Redirect based on onboarding status if (result.user.location) { navigate('/dashboard'); } else { navigate('/onboarding/user'); } } catch (err) { console.error('[Login] Email login failed:', err); setError((err as Error).message || 'Login failed'); } }; const handleGithubLogin = async () => { try { setIsGithubLoading(true); const result = await signInWithGitHub(); // Check if we got a redirect URL if (result?.url) { globalThis.location.href = result.url; } else { setIsGithubLoading(false); setError('Failed to get GitHub OAuth URL'); } } catch (err) { console.error('[Login] GitHub login failed:', err); setError((err as Error).message || 'GitHub login failed'); setIsGithubLoading(false); } }; return (

Welcome Back

Sign in to join or create your hackathon team

{error && (

{error}

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

); }