mirror of
https://github.com/hanzoai/computer.git
synced 2026-09-30 20:55:46 +00:00
Add complete Supabase integration for data persistence and authentication: Backend Setup: - Created Supabase client configuration (src/lib/supabase.ts) - Defined TypeScript interfaces for all database tables - Implemented helper functions for RFQ and cluster request submission - Added functions for customer data retrieval (quotes, orders, subscriptions) - Added admin functions for managing all requests Database Schema (supabase/schema.sql): - 10 tables: users, rfqs, cluster_requests, quotes, orders, subscriptions, invoices, gpu_reservations, usage_records, admin_actions - Row Level Security (RLS) policies for customer/admin access control - Indexes for query performance - Triggers for automatic timestamp updates - Complete foreign key relationships Security Features: - RLS policies: Customers can only view their own data - Admins can view and manage all data - Anonymous users can submit RFQs and cluster requests - Automatic timestamp management - Secure credential storage Form Integration: - Request Quote page now submits to Supabase rfqs table - Clusters page now submits to Supabase cluster_requests table - Both forms include proper error handling and success messages - Duration converted to months for database storage Configuration: - .env.example with Supabase URL and API key placeholders - supabase/README.md with comprehensive setup instructions - Project ID: fefkbezinxawrutwjdkq - Region: us-east-1 Helper Functions: - submitRFQ() - Submit request for quote - submitClusterRequest() - Submit cluster inquiry - getUserRFQs/Quotes/Orders/Subscriptions() - Customer data retrieval - getAllRFQs/ClusterRequests() - Admin data retrieval - updateRFQStatus/ClusterRequestStatus() - Admin workflow management Next Steps: 1. Run schema.sql in Supabase SQL Editor 2. Configure environment variables in .env.local 3. Test RFQ and cluster request submissions 4. Build customer dashboard to view submitted requests 5. Build admin dashboard to manage requests and send quotes
Supabase Setup for Hanzo.Computer
This directory contains the database schema and setup instructions for the Hanzo.Computer leasing platform.
Database Information
Project ID: fefkbezinxawrutwjdkq
Region: us-east-1
Database URL: postgresql://postgres:[PASSWORD]@db.fefkbezinxawrutwjdkq.supabase.co:5432/postgres
Supabase URL: https://fefkbezinxawrutwjdkq.supabase.co
Setup Instructions
1. Initialize Database
- Go to Supabase SQL Editor: https://supabase.com/dashboard/project/fefkbezinxawrutwjdkq/sql
- Run the
schema.sqlfile to create all tables and policies - Verify tables are created in Table Editor
2. Configure Environment Variables
Copy .env.example to .env.local:
cp .env.example .env.local
Get your Supabase API keys:
- Go to Project Settings → API
- Copy the Project URL (already in .env.example)
- Copy the
anonpublic key toVITE_SUPABASE_ANON_KEY
3. Test Database Connection
npm run dev
Try submitting an RFQ or cluster request to verify the connection.
Database Schema
Core Tables
- users: User profiles (extends Supabase auth)
- rfqs: Request for Quote submissions
- cluster_requests: GPU cluster inquiries
- quotes: Admin-generated quotes
- orders: Accepted quotes or direct purchases
- subscriptions: Recurring GPU leasing subscriptions
- invoices: Generated invoices (Stripe or manual)
- gpu_reservations: Provisioned GPU instances
- usage_records: GPU usage tracking
- admin_actions: Audit log for admin operations
Row Level Security (RLS)
All tables have RLS policies:
- Customers can create RFQs/cluster requests and view their own data
- Admins can view and manage all data
- Anonymous users can submit RFQs (unauthenticated)
Admin Setup
To create an admin user:
- Sign up via the app (creates a customer user)
- In Supabase SQL Editor, run:
UPDATE public.users
SET role = 'admin'
WHERE email = '[email protected]';
API Functions
Helper functions in src/lib/supabase.ts:
Customer Functions:
submitRFQ()- Submit request for quotesubmitClusterRequest()- Submit cluster inquirygetUserRFQs()- Get user's RFQsgetUserQuotes()- Get user's quotesgetUserOrders()- Get user's ordersgetUserSubscriptions()- Get user's subscriptions
Admin Functions:
getAllRFQs()- Get all RFQs (with optional status filter)getAllClusterRequests()- Get all cluster requestsupdateRFQStatus()- Update RFQ statusupdateClusterRequestStatus()- Update cluster request status
Integration with Forms
Both RFQ and Clusters pages use Supabase for data persistence:
Request Quote (/request-quote):
- Submits to
rfqstable viasubmitRFQ()
Clusters (/clusters):
- Submits to
cluster_requeststable viasubmitClusterRequest()
Next Steps
- ✅ Database schema created
- ✅ RLS policies configured
- ⏳ Create admin dashboard to view RFQs/cluster requests
- ⏳ Build quote generation workflow
- ⏳ Integrate Stripe for payments
- ⏳ Build customer dashboard
Troubleshooting
Connection errors:
- Verify Supabase URL and anon key in
.env.local - Check project is not paused in Supabase dashboard
RLS errors:
- Verify policies are enabled:
SELECT * FROM pg_policies WHERE tablename = 'rfqs'; - Test with authenticated vs. unauthenticated requests
Missing tables:
- Re-run
schema.sqlin SQL Editor - Check for SQL errors in execution logs