| 76 | const handleGithubLogin = () => login("github"); |
| 77 | |
| 78 | const handleEmailLogin = async (e) => { |
| 79 | e.preventDefault(); |
| 80 | |
| 81 | if (!captchaToken) { |
| 82 | toast({ |
| 83 | variant: "destructive", |
| 84 | title: "Verification Required", |
| 85 | description: "Please complete the CAPTCHA verification.", |
| 86 | }); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | setIsLoading(true); |
| 91 | try { |
| 92 | const res = await subdomainAPI.post('/auth/email/login', { |
| 93 | email, |
| 94 | password, |
| 95 | captchaToken |
| 96 | }); |
| 97 | |
| 98 | // Check if 2FA is required |
| 99 | if (res.requires2FA) { |
| 100 | toast({ |
| 101 | title: "2FA Required", |
| 102 | description: "Redirecting to verification...", |
| 103 | }); |
| 104 | window.location.href = `/verify-2fa?email=${encodeURIComponent(res.email || email)}`; |
| 105 | return; |
| 106 | } |
| 107 | |
| 108 | if (res.success) { |
| 109 | // Force full page reload to refresh auth context |
| 110 | window.location.href = '/dashboard'; |
| 111 | } |
| 112 | } catch (err) { |
| 113 | if (err.status === 403) { |
| 114 | if (err.message === 'Please verify your email address first.') { |
| 115 | toast({ |
| 116 | title: "Verification Required", |
| 117 | description: "Redirecting to verification page...", |
| 118 | }); |
| 119 | window.location.href = `/verify-email?email=${encodeURIComponent(email)}`; |
| 120 | return; |
| 121 | } |
| 122 | |
| 123 | if (err.data && err.data.error === 'profile_incomplete') { |
| 124 | toast({ |
| 125 | title: "Profile Completion Required", |
| 126 | description: "Redirecting to complete your profile...", |
| 127 | }); |
| 128 | window.location.href = `/complete-profile?email=${encodeURIComponent(email)}`; |
| 129 | return; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | toast({ |
| 134 | variant: "destructive", |
| 135 | title: "Login Failed", |