'use client'; import React, { useState } from 'react'; import { useRouter } from 'next/navigation'; import Link from 'next/link'; import { Card, CardHeader, CardTitle, CardContent } from '@/components/ui/Card'; import { Input } from '@/components/ui/Input'; import { Button } from '@/components/ui/Button'; import { useTranslation } from '@/hooks/useTranslation'; import { useCsrf } from '@/hooks/useCsrf'; export default function SignupPage() { const router = useRouter(); const { t } = useTranslation(); const { fetchWithCsrf } = useCsrf(); const [name, setName] = useState(''); const [email, setEmail] = useState(''); const [password, setPassword] = useState(''); const [confirmPassword, setConfirmPassword] = useState(''); const [loading, setLoading] = useState(false); const [error, setError] = useState(''); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); setLoading(true); setError(''); if (password !== confirmPassword) { setError('Passwords do not match'); setLoading(false); return; } if (password.length < 8) { setError('Password must be at least 8 characters'); setLoading(false); return; } try { const response = await fetchWithCsrf('/api/auth/signup', { method: 'POST', body: JSON.stringify({ name, email, password }), }); const data = await response.json(); if (response.ok && data.success) { // Store user in localStorage for client-side localStorage.setItem('user', JSON.stringify(data.user)); // Track successful signup with PostHog try { const { identifyUser, trackEvent } = await import('@/components/PostHogProvider'); identifyUser(data.user.id, { email: data.user.email, name: data.user.name, plan: data.user.plan || 'FREE', signupMethod: 'email', }); trackEvent('user_signup', { method: 'email', email: data.user.email, }); } catch (error) { console.error('PostHog tracking error:', error); } // Redirect to dashboard router.push('/dashboard'); router.refresh(); } else { setError(data.error || 'Failed to create account'); } } catch (err) { setError('An error occurred. Please try again.'); } finally { setLoading(false); } }; const handleGoogleSignIn = () => { // Redirect to Google OAuth API route window.location.href = '/api/auth/google'; }; return (
QR Master QR Master

Create Account

Start creating QR codes in seconds

← Back to Home
{error && (
{error}
)} setName(e.target.value)} placeholder="John Doe" required /> setEmail(e.target.value)} placeholder="you@example.com" required /> setPassword(e.target.value)} placeholder="••••••••" required /> setConfirmPassword(e.target.value)} placeholder="••••••••" required />
Or continue with

Already have an account?{' '} Sign in

By signing up, you agree to our{' '} Privacy Policy

); }