# SceneKey Store Setup Guide

## 1. Supabase Database Setup

### Create Supabase Project
1. Go to [supabase.com](https://supabase.com) and create a new project
2. Note your project URL and keys

### Run Database Schema
1. In your Supabase dashboard, go to **SQL Editor**
2. Copy the entire contents of `lib/schema.sql`
3. Paste it into the SQL Editor and click **Run**
4. This will create all tables with proper RLS policies

### Get API Keys
In your Supabase dashboard:
1. Go to **Settings** > **API**
2. Copy the **Project URL** (this is `NEXT_PUBLIC_SUPABASE_URL`)
3. Copy the **anon public** key (this is `NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY`)
4. Copy the **service_role** key (this is `SUPABASE_SERVICE_ROLE_KEY`)

### Update .env file
Replace the Supabase values in your `.env` file:
```env
NEXT_PUBLIC_SUPABASE_URL=https://your-project-id.supabase.co
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=your-anon-key-here
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key-here
```

## 2. Seed the Database

After running the schema, populate with sample data:
```bash
npx tsx lib/seed.ts
```

This will create:
- 8 categories (Laptops, Phones, TVs, Headphones, Cameras, Tablets, Smart Home, Gaming)
- 12 products (including 2 auction items)
- Payvato installment plans for eligible products

## 3. Start the Development Server

```bash
npm run dev
```

Visit `http://localhost:3000` to see your store!

## 4. Test Features

- **Authentication**: Register/login with custom JWT (no Supabase Auth)
- **Products**: Browse, search, filter products
- **Cart**: Add items, adjust quantities
- **Checkout**: Address form with zip validation
- **Auctions**: Live countdown timers on auction products
- **Payvato**: Installment plans on eligible products
- **Emails**: Check your SMTP emails for stylish notifications

## 5. Environment Variables Reference

Your `.env` should contain:
```env
# Supabase (required)
NEXT_PUBLIC_SUPABASE_URL=https://your-project.supabase.co
NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY=your-anon-key
SUPABASE_SERVICE_ROLE_KEY=your-service-role-key

# Custom Auth (required)
JWT_SECRET=your-super-secret-jwt-key-change-this-in-production
ENCRYPTION_KEY=0123456789abcdef0123456789abcdef

# SMTP for emails (required)
SMTP_HOST=mail.scenekey.com
SMTP_PORT=465
SMTP_SECURE=true
SMTP_USER=mail@scenekey.com
SMTP_PASS=your-smtp-password

# Stripe (optional)
STRIPE_SECRET_KEY=sk_test_xxx
STRIPE_PUBLISHABLE_KEY=pk_test_xxx
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_xxx

# App URL
NEXT_PUBLIC_APP_URL=http://localhost:3000
```

## 6. Troubleshooting

### "Invalid API key" error
- Check that you're using the correct keys from Supabase Settings > API
- Ensure the service_role key is being used for admin operations
- Verify the NEXT_PUBLIC_SUPABASE_URL matches your project URL

### Database not found
- Make sure you ran the schema.sql in Supabase SQL Editor
- Check that all tables were created successfully

### Emails not sending
- Verify SMTP settings in .env
- Check that mail.scenekey.com is accessible
- Ensure SMTP_PASS is correct

## 7. Production Deployment

When deploying to production:
1. Update NEXT_PUBLIC_APP_URL to your production domain
2. Change JWT_SECRET to a new secure value
3. Update SMTP settings for production email server
4. Set up Stripe production keys if using payments
5. Run the schema and seed script on your production Supabase project

## 8. Features Implemented

- **Custom JWT Authentication** (no Supabase Auth)
- **Stylish Branded Emails** via SMTP
- **Auction Countdown Timers**
- **Payvato Pay-Over-Time Integration**
- **Zip Code Validation** (5-digit numeric only)
- **Address Autocomplete** (ready for Google Places API)
- **Remember Login** functionality
- **Save Credit Cards** option
- **Full Shopping Cart & Checkout**
- **Wishlist & Account Management**
- **Order History & Tracking**
- **Product Reviews & Ratings**
- **Responsive Design** (exact UI preserved)

The migration is complete! Your static electronics marketplace is now a dynamic Next.js application with Supabase backend.
