This folder contains a small blueprint with example files for a private one-to-one chat using Next.js App Router (14+), Tailwind CSS, TypeScript and Supabase (Realtime + Storage).
Files added (overview):
lib/supabase.ts- Browser Supabase client factorylib/supabase-server.ts- Server factory (for server components/actions)hooks/useRealtimeMessages.ts- Hook to subscribe to INSERTs onmessageshooks/useAuth.ts- Lightweight client auth hookcomponents/ChatMessage.tsx- Message renderercomponents/ChatInput.tsx- Input with image uploadcomponents/AppLock.tsx- Privacy overlay (blurs when window loses focus)app/chat/layout.tsx- Wraps chat routes withAppLockapp/chat/page.tsx- Client chat page example (hardcoded RECEIVER_ID).env.example- env var placeholders
Scripts:
npm run create-test-users- create two chat users (alice,bob) and one admin (admin) inprofilesusing the service role key and the database RPCset_user_password.
How to create test users (no email):
- Copy
.env.exampleto.env.localand fill inNEXT_PUBLIC_SUPABASE_URLandSUPABASE_SERVICE_ROLE_KEYandAUTH_SECRET. - Run:
npm run create-test-usersThis will insert three rows into public.profiles and call the public.set_user_password RPC to set their passwords.
Notes:
- These files are a blueprint and intentionally minimal. They assume you have a Next.js app, Tailwind and React set up. You may need to adapt import paths or add
tsconfig.jsonpath aliases if you prefer@/...imports. - TypeScript/React types may show lint errors in this workspace until you install dependencies (
react,@types/react,next, etc.). - Replace
RECEIVER_IDinapp/chat/page.tsxwith the ID of the contact you want to chat with.
Next steps (suggested):
- Install peer deps for a Next app if you haven't already:
npm install react react-dom next
npm install -D typescript @types/react @types/node- Add Tailwind and shadcn UI if desired.
- Run
npm run devafter configuringnext.config.jsandtsconfig.json.