<!-- STREAM_EPOCH: 1 | OLDEST_STEP: 1 | LATEST_STEP: 7 -->
# Live AI-IDE Build Broadcast Stream — Dima Tipikin x FractalOps
- **Stream Page:** https://fractalops.ai/webinar
- **Latest Step Only (.MD):** https://fractalops.ai/api/webinar?step=latest&format=raw
- **Delta Feed Since Step K (.MD):** https://fractalops.ai/api/webinar?after=7&format=raw
- **60s Bonus & Feedback (.MD):** https://fractalops.ai/feedback?format=raw
- **Total Published Steps:** 7 · **Latest Step #:** 7

<!-- BEGIN_STEP_7 sha256=7498cffcc97f2e43ba89c7d4a0255a75ceabcc4ed5a5b7dbef5d9e486496158e created_at=2026-11-13T17:49:57.903Z -->
## Step #7 [LATEST_STEP] — Kids Tutor Without Registration
- **Step Number:** `7` · **Published UTC:** `2026-11-13T17:49:57.903Z` · **Author:** `Dima Tipikin · Cursor Live` · **Size:** `6203 B` · **SHA-256:** `7498cffcc97f2e43`

# Kids Tutor Without Registration

The main page no longer redirects to login. A child immediately sees the tutor: "Math" and "Reading" buttons, followed by "Give me a task". There is no email or password form on this screen.

The server automatically creates a single demo user `child@wildzebra.local`, a child named "Zebra", Grade 3, hobby "cats", and a session for the selected subject. The session identifier is stored in the `wz_play` cookie. If no one is logged in, `/api/task` and `/api/chat` operate under this user. The task answer is still written exclusively by the server to `task_answers`.

On the public link, the daily limit is shared: 15 tasks and 40 chat messages for this demo user. On your own instance, the limit is separate because it uses your own Supabase project.

## What to Connect

1. Supabase project. Run `wild-zebra/supabase/migration.sql` once in the SQL Editor.
2. In `.env.local` and in Vercel environment variables (Production and Preview), add three variable names, without quotes and without sharing these values in chat:
   - `NEXT_PUBLIC_SUPABASE_URL`
   - `NEXT_PUBLIC_SUPABASE_ANON_KEY`
   - `SUPABASE_SERVICE_ROLE_KEY`
3. `NEXT_PUBLIC_` is included in the build. After setting the variables, a new deployment is required; the old build will not see them.
4. In the Supabase dashboard, disable Confirm email. The demo user is created already confirmed, but regular registration without this flag will halt waiting for an email.
5. The OpenRouter key is already read on the server: `WILDZEBRA_OPENROUTER_API_KEY` or `OPENROUTER_API_KEY`. Model: `OPENROUTER_MODEL`, defaults to `google/gemini-2.5-flash-lite`.

## lib/db.ts

`currentUserId` first checks the login cookie. If there is no user, it falls back to the demo parent. The demo user password is generated on the server and is not saved anywhere.

```ts
const DEMO_EMAIL = "child@wildzebra.local";
let cachedDemoParentId: string | null = null;

export async function demoParentId(): Promise<string> {
  if (cachedDemoParentId) return cachedDemoParentId;
  const url = process.env.NEXT_PUBLIC_SUPABASE_URL;
  const key = process.env.SUPABASE_SERVICE_ROLE_KEY;
  if (!url || !key) throw new Error("Net SUPABASE_SERVICE_ROLE_KEY");
  const headers = { apikey: key, Authorization: `Bearer ${key}`, "Content-Type": "application/json" };
  const listed = await fetch(`${url}/auth/v1/admin/users?page=1&per_page=200`, { headers });
  const body = (await listed.json().catch(() => null)) as { users?: { id: string; email?: string }[] } | null;
  const existing = body?.users?.find((user) => user.email === DEMO_EMAIL);
  if (existing) {
    cachedDemoParentId = existing.id;
    return existing.id;
  }
  const admin = createAdmin();
  const { data, error } = await admin.auth.admin.createUser({
    email: DEMO_EMAIL,
    password: `${crypto.randomUUID()}Aa1`,
    email_confirm: true,
  });
  if (!data.user) throw new Error(error?.message ?? "Ne sozdalsya demo-polzovatel");
  cachedDemoParentId = data.user.id;
  return data.user.id;
}

export async function ensurePlaySession(subject: Subject, sessionId: string | null): Promise<string> {
  const parentId = await demoParentId();
  const admin = createAdmin();
  if (sessionId) {
    const { data: session } = await admin
      .from("sessions")
      .select("id,subject")
      .eq("id", sessionId)
      .eq("parent_id", parentId)
      .maybeSingle();
    if (session && session.subject === subject) return session.id;
  }
  const { data: child } = await admin.from("children").select("id").eq("parent_id", parentId).limit(1).maybeSingle();
  let childId = child?.id as string | undefined;
  if (!childId) {
    const inserted = await admin
      .from("children")
      .insert({ parent_id: parentId, nickname: "Zebra", grade: 3, hobby: "kotiki" })
      .select("id")
      .single();
    if (inserted.error || !inserted.data) throw new Error(inserted.error?.message ?? "Ne sozdalsya rebyonok");
    childId = inserted.data.id;
  }
  const created = await admin
    .from("sessions")
    .insert({ parent_id: parentId, child_id: childId, subject })
    .select("id")
    .single();
  if (created.error || !created.data) throw new Error(created.error?.message ?? "Ne sozdalas sessiya");
  return created.data.id;
}

export async function currentUserId(): Promise<string | null> {
  try {
    const supabase = await createClient();
    const { data } = await supabase.auth.getUser();
    if (data.user?.id) return data.user.id;
  } catch {
    return null;
  }
  try {
    return await demoParentId();
  } catch {
    return null;
  }
}
```

## app/api/play/route.ts

`POST { subject: "math" | "reading" }`. Response: `{ sessionId, subject, task }`. Cookie `wz_play` valid for 30 days. `task` is the latest task in this session without a correct answer.

## app/page.tsx

If the three Supabase variables are missing, the page displays which variable names need to be added. If present, it renders `ChildTutor`: automatically opens math, while "Reading" switches the subject.

## Verified

https://wild-zebra.vercel.app opens without login. Math initialized a session, "Give me a task" returned a cat-themed problem, 3 out of 3 attempts remaining. There is no correct answer in the page source.

<!-- END_STEP_7 -->
---
