Get your API key

Lesson 5 of 5

Save chats and launch

Supabase login, chats and messages with RLS, delete and a privacy note, a two-user test, then live on Vercel with a separate key.

9 min Log in to open
One step at a time, like flipping pages.

By the end of this lesson your bot will have logins, saved chats that only their owner can see, a delete button and an honest privacy note, and it will be live on Vercel with its key safely in environment variables.

You need: the app from lesson 4, a free Supabase account, GitHub and Vercel accounts (all set up in First web MVP) · Time: 9 minutes

  1. Saved chats need an owner, and a public bot needs to know who is sending each message. So login comes first. You will use Supabase Auth, the same login system as in First web MVP. If you have not done that lesson, read Save data properly before you start; it explains the publishable key, the secret key and RLS.

    Create a new Supabase project called exam-buddy, then paste:

    Prompt · copy it into your AI agent
    Goal: Add email and password login to Exam Buddy with Supabase Auth, and protect the chat route.
    Context: Next.js App Router app. Supabase project URL and publishable key will go in .env.local as NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY. Read the Route Handlers guide in node_modules/next/dist/docs/ if it exists before changing routes.
    Details:
    - Use the official Supabase packages for Next.js server-side auth (cookies). Add Sign up, Log in and Log out pages.
    - The chat page is only for logged-in users; logged-out visitors go to Log in.
    - POST /api/chat reads the logged-in user on the server. No user means status 401 and the model is NOT called.
    - Change lib/limits.ts to limit by user id instead of IP. Keep the same numbers.
    Rules:
    - Never use the Supabase secret key in this app. The publishable key is fine because RLS will protect every table.
    - ALLMODELAPI_KEY stays server-only, as before.
    Done when: logged out, I cannot reach the chat and a direct POST to /api/chat returns 401; logged in, chat works as before.
    Why?

    Without login, your rate limits can be dodged by switching Wi-Fi, and anyone on the internet can use your bot on your bill. With login, every message has a name attached and every limit sticks.

Log in free to read the rest of this lesson

Every lesson is free. A free account unlocks all of them and saves your progress.

Still to come in this lesson:

  1. Two tables, owned by their user
  2. Past chats, delete, and a privacy note
  3. Test with two users
  4. Go live on Vercel
  5. Last checks before you share the link
  6. Recap