import React, { useState } from 'react'; import axios from 'axios'; import { useAuth } from '../AuthContext'; import { useNavigate, Link } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { Tooltip } from '../components/Tooltip'; import { LegalModal } from '../components/LegalModal'; import { ShieldCheck, FileText, AlertTriangle, Key } from 'lucide-react'; import { GoogleLogin } from '@react-oauth/google'; export default function Signup() { const { t } = useTranslation(); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [etsyShopName, setEtsyShopName] = useState(''); const [etsyShopLink, setEtsyShopLink] = useState(''); // New Fields for Phase 6 const [apiKey, setApiKey] = useState(''); const [termsAccepted, setTermsAccepted] = useState(false); const [kvkkAccepted, setKvkkAccepted] = useState(false); // UI State const [error, setError] = useState<{ message: string, code?: string } | null>(null); const [isSubmitting, setIsSubmitting] = useState(false); const [modalType, setModalType] = useState<'terms' | 'kvkk' | null>(null); const { login } = useAuth(); const navigate = useNavigate(); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setError(null); // Frontend Verification if (!termsAccepted || !kvkkAccepted) { setError({ message: "You must accept both the User Agreement and KVKK to register." }); return; } if (apiKey.length < 20) { setError({ message: "Please enter a valid Gemini API Key." }); return; } setIsSubmitting(true); try { const res = await axios.post('/api/auth/register', { email, password, apiKey, etsyShopName, etsyShopLink, termsAccepted: true // Backend checks this }); login(res.data.token, res.data.user); navigate('/'); } catch (err: any) { const data = err.response?.data; const code = data?.code || 'UNKNOWN_ERROR'; const msg = data?.error || 'Registration failed. Please try again.'; setError({ message: msg, code }); } finally { setIsSubmitting(false); } }; return (
Join the Beta access program
{error.message}
{error.code === 'INVALID_KEY' && (Tip: Keys usually start with AIza...
)}Already have an account? Log in