'use client';
import { useState, Suspense } from 'react';
import { useRouter, useSearchParams } from 'next/navigation';
import { useAuth } from '@/contexts/AuthContext';
import { trackSignup } from '@/lib/analytics';
import Wordmark from '@/components/Wordmark';
import { GoogleIcon, AppleIcon, XIcon } from '@/components/OAuthIcons';
function SignupInner() {
const router = useRouter();
const search = useSearchParams();
const next = search.get('next') || '/dashboard';
const { signUp, signInWithProvider } = useAuth();
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [confirm, setConfirm] = useState('');
const [ageOk, setAgeOk] = useState(false);
const [error, setError] = useState('');
const [busy, setBusy] = useState(false);
const [done, setDone] = useState(false);
const handleSignup = async (e: React.FormEvent) => {
e.preventDefault();
setError('');
if (password.length < 8) return setError('Password must be at least 8 characters.');
if (password !== confirm) return setError('Passwords do not match.');
if (!ageOk) return setError('You must confirm you are 21 or older.');
setBusy(true);
const { error: err } = await signUp(email, password, ageOk);
setBusy(false);
if (err) {
setError(err);
return;
}
trackSignup({ method: 'password' });
setDone(true);
// Supabase confirms via email by default. If session is immediate, redirect.
setTimeout(() => router.replace(next), 1500);
};
// Session 13 — generic OAuth dispatch. Same provider buttons as
// the login page; same graceful-error contract for unconfigured
// providers (Apple/X).
const handleOAuth = async (provider: 'google' | 'apple' | 'twitter') => {
setBusy(true);
setError('');
const { error: err } = await signInWithProvider(provider);
if (err) {
setError(err);
setBusy(false);
}
};
if (done) {
return (
✓
You're in.
Check your email for a confirmation link, then come back and grade something.
);
}
return (
Get started — free
5 free reads every month. Your first read is fully unlocked. No credit card.
{/* Session 14 — OAuth buttons with provider icons. Same
ProviderButton helper as /login (inlined here to avoid a
new shared module for two callsites). */}