diff --git a/web/src/App.tsx b/web/src/App.tsx index 2ca6a4c..65f5012 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -5,15 +5,29 @@ import { Preview } from './components/Preview.tsx'; import { SignUp } from './components/SignUp.tsx'; import { useChat } from './hooks/useChat.ts'; -export function App() { - const [signedUp, setSignedUp] = useState(false); - const [applied, setApplied] = useState(false); - const chat = useChat(); +async function signUp(email: string, password: string): Promise { + const res = await fetch('/auth/signup', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ email, password }), + }); + if (!res.ok) { + const body = (await res.json().catch(() => null)) as { error?: string } | null; + throw new Error(body?.error ?? 'Sign up failed'); + } + const body = (await res.json()) as { sessionToken: string }; + return body.sessionToken; +} - if (!signedUp) { +export function App() { + const [sessionToken, setSessionToken] = useState(null); + const [applied, setApplied] = useState(false); + const chat = useChat(sessionToken); + + if (sessionToken === null) { return (
- setSignedUp(true)} /> + setSessionToken(await signUp(email, password))} />
); } diff --git a/web/src/components/ChatPanel.tsx b/web/src/components/ChatPanel.tsx index 92c6426..829ff67 100644 --- a/web/src/components/ChatPanel.tsx +++ b/web/src/components/ChatPanel.tsx @@ -30,7 +30,7 @@ export function ChatPanel({ messages, status, onSend }: ChatPanelProps) { ) : (