Get your API key

Lesson 5 mein se 5

Chats save karo aur launch

Supabase login, RLS ke saath chats aur messages, delete aur privacy note, two-user test, phir alag key ke saath Vercel par live.

9 min Login karke kholo
Ek baar mein ek step, page palatne jaisa.

Is lesson ke end tak aapke bot mein login hoga, saved chats jo sirf unka owner dekh sake, ek delete button aur ek imaandaar privacy note, aur woh Vercel par live hoga, key environment variables mein safe.

Aapko chahiye: lesson 4 wala app, ek free Supabase account, GitHub aur Vercel accounts (sab First web MVP mein set up hue) · Time: 9 minute

  1. Saved chats ko ek owner chahiye, aur public bot ko pata hona chahiye ki har message kaun bhej raha hai. Isliye pehle login. Aap Supabase Auth use karoge, wahi login system jo First web MVP mein tha. Woh lesson nahi kiya, toh shuru karne se pehle Save data properly padh lo; usmein publishable key, secret key aur RLS samjhaaye gaye hain.

    exam-buddy naam ka naya Supabase project banao, phir yeh paste karo:

    Prompt · ise apne AI agent mein paste karo
    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.
    Kyun?

    Login ke bina aapki rate limits Wi-Fi badalkar chakma di ja sakti hain, aur internet par koi bhi aapke bill par bot chala sakta hai. Login ke saath har message par ek naam hota hai aur har limit tikti hai.

Baaki lesson padhne ke liye free login karo

Har lesson free hai. Free account se saare lessons khul jaate hain aur aapki progress save hoti hai.

Is lesson mein aage:

  1. Do tables, apne user ki
  2. Purani chats, delete, aur privacy note
  3. Do users ke saath test karo
  4. Vercel par live karo
  5. Link share karne se pehle aakhri checks
  6. Recap