# Fix JWT Verification Issue - Quick Guide

## Problem
The Edge Functions are rejecting public requests (like `/auth/signup`) because JWT verification is enabled by default.

## Solution Options

### Option 1: Manual Dashboard Update (If Available in Future)
1. Go to: https://supabase.com/dashboard/project/ztklqodcdjeqpsvhlpud/settings/functions
2. Look for Edge Functions settings
3. Disable JWT verification for each function

---

### Option 2: Using Supabase CLI (Recommended)

#### Step 1: Install Supabase CLI
```bash
# On Linux/macOS
npm install -g supabase

# Or with homebrew (macOS)
brew install supabase/tap/supabase
```

#### Step 2: Login to Supabase
```bash
supabase login
```
This will open your browser to authenticate.

#### Step 3: Link Your Project
```bash
cd /data/shopcall
supabase link --project-ref ztklqodcdjeqpsvhlpud
```

#### Step 4: Redeploy Functions with Correct Configuration
```bash
# The config.toml file has already been created with verify_jwt = false

# Redeploy all functions
cd /data/shopcall
supabase functions deploy auth --no-verify-jwt
supabase functions deploy shopify-oauth --no-verify-jwt
supabase functions deploy woocommerce-oauth --no-verify-jwt
supabase functions deploy gdpr-webhooks --no-verify-jwt
```

---

### Option 3: Using Management API (Advanced)

If you have your Supabase service role key, you can update via API:

```bash
# Get your service role key from:
# https://supabase.com/dashboard/project/ztklqodcdjeqpsvhlpud/settings/api

# Set environment variable
export SUPABASE_SERVICE_KEY="your_service_role_key_here"

# Update each function
for func in auth shopify-oauth woocommerce-oauth gdpr-webhooks; do
  curl -X PATCH "https://api.supabase.com/v1/projects/ztklqodcdjeqpsvhlpud/functions/$func" \
    -H "Authorization: Bearer $SUPABASE_SERVICE_KEY" \
    -H "Content-Type: application/json" \
    -d '{"verify_jwt": false}'
done
```

---

### Option 4: Quick Fix Script

I've created a script for you. Save this as `fix-jwt.sh`:

```bash
#!/bin/bash

echo "Installing Supabase CLI..."
npm install -g supabase

echo "Please login to Supabase (browser will open)..."
supabase login

echo "Linking to your project..."
cd /data/shopcall
supabase link --project-ref ztklqodcdjeqpsvhlpud

echo "Deploying functions with JWT verification disabled..."
supabase functions deploy auth --no-verify-jwt
supabase functions deploy shopify-oauth --no-verify-jwt
supabase functions deploy woocommerce-oauth --no-verify-jwt
supabase functions deploy gdpr-webhooks --no-verify-jwt

echo "Done! Try signup again at https://shopcall.ai/signup"
```

Then run:
```bash
chmod +x fix-jwt.sh
./fix-jwt.sh
```

---

## Verification

After applying the fix, test the signup:
1. Go to: https://shopcall.ai/signup
2. Fill in the form and submit
3. You should receive an OTP email
4. No more "401 Unauthorized" errors

## What Changed

The configuration file at `/data/shopcall/supabase/config.toml` now includes:

```toml
[functions.auth]
verify_jwt = false

[functions.shopify-oauth]
verify_jwt = false

[functions.woocommerce-oauth]
verify_jwt = false

[functions.gdpr-webhooks]
verify_jwt = false
```

This allows the functions to handle authentication internally without requiring a JWT token for every request.

## Need Help?

If you encounter any issues:
1. Check the Edge Functions logs: https://supabase.com/dashboard/project/ztklqodcdjeqpsvhlpud/logs/edge-functions
2. Verify the function is deployed correctly
3. Check the browser console for detailed error messages
