| 8 | import { Turnstile } from '@marsidev/react-turnstile'; |
| 9 | |
| 10 | export default function Login() { |
| 11 | const { login } = useAuth(); |
| 12 | const [activeTab, setActiveTab] = useState('github'); |
| 13 | const [email, setEmail] = useState(''); |
| 14 | const [password, setPassword] = useState(''); |
| 15 | const [showPassword, setShowPassword] = useState(false); |
| 16 | const [isLoading, setIsLoading] = useState(false); |
| 17 | const [errorBanner, setErrorBanner] = useState(null); |
| 18 | const [captchaToken, setCaptchaToken] = useState(import.meta.env.DEV ? "dev-bypass" : ""); |
| 19 | const [searchParams] = useSearchParams(); |
| 20 | const error = searchParams.get('error'); |
| 21 | const { toast } = useToast(); |
| 22 | |
| 23 | useEffect(() => { |
| 24 | if (error) { |
| 25 | let title = "Login Failed"; |
| 26 | let description = "An unknown error occurred."; |
| 27 | |
| 28 | switch (error) { |
| 29 | case 'banned': |
| 30 | title = "Account Suspended"; |
| 31 | description = "Your account has been banned for violating our terms."; |
| 32 | break; |
| 33 | case 'registration_closed': |
| 34 | title = "Registration Closed"; |
| 35 | description = "New sign-ups are currently disabled by the administrator."; |
| 36 | break; |
| 37 | case 'github_failed': |
| 38 | title = "Authentication Failed"; |
| 39 | description = "Could not sign in with GitHub. Please try again later."; |
| 40 | break; |
| 41 | case 'server_error': |
| 42 | title = "Server Error"; |
| 43 | description = "Something went wrong on our end. Please try later."; |
| 44 | break; |
| 45 | case 'github_account_too_new': |
| 46 | const daysRequired = searchParams.get('days') || '7'; |
| 47 | title = "Account Looks Suspicious"; |
| 48 | description = `Your GitHub account appears to be recently created. We cannot proceed at this time. Please refrain from using alt or spam accounts. If you believe this is a mistake, please contact support. (Account must be at least 7 days old, ${daysRequired} day(s) remaining)`; |
| 49 | break; |
| 50 | case 'no_public_email': |
| 51 | title = "Public Email Required"; |
| 52 | description = "We need a public email from your GitHub account to create your account and send important notifications."; |
| 53 | break; |
| 54 | case 'registration_closed_use_email': |
| 55 | title = "GitHub Signups Paused"; |
| 56 | description = "New accounts must use Email/Password. Existing users can still login with GitHub."; |
| 57 | setActiveTab('email'); |
| 58 | break; |
| 59 | default: |
| 60 | title = "Login Failed"; |
| 61 | description = error || "An unknown error occurred. Please try again."; |
| 62 | break; |
| 63 | } |
| 64 | |
| 65 | setErrorBanner({ title, description }); |
| 66 | |
| 67 | toast({ |