Files
ocean-cleanup/server/CLERK_SETUP.md
Paul Bailey d80e787701 docs: add Clerk setup guide and improve auth error messages
- Create CLERK_SETUP.md with step-by-step instructions
- Improve error message to indicate Clerk configuration issue
- Remove debug logging from auth middleware
- Update error handling to be more helpful

The 401 error is caused by missing Clerk Secret Key in server/.env
2025-11-16 19:23:37 +00:00

82 lines
2.3 KiB
Markdown

# Clerk Authentication Setup
## Issue
The backend server is returning 401 Unauthorized errors because the Clerk Secret Key is not configured correctly.
**Error**: `The provided Clerk Secret Key is invalid. Make sure that your Clerk Secret Key is correct.`
## Solution
You need to add your real Clerk Secret Key to the backend environment configuration.
### Steps to Fix
1. **Get your Clerk Secret Key**:
- Go to [Clerk Dashboard](https://dashboard.clerk.com)
- Navigate to **API Keys** section
- Copy your **Secret Key** (starts with `sk_test_...` for test environment or `sk_live_...` for production)
2. **Update the backend .env file**:
- Open `server/.env`
- Replace the placeholder with your real secret key:
```env
# Before (placeholder)
CLERK_SECRET_KEY="sk_test_placeholder"
# After (your real key)
CLERK_SECRET_KEY="sk_test_YOUR_ACTUAL_SECRET_KEY_HERE"
```
3. **Restart the backend server**:
- The server will automatically restart if you're using `npm run dev`
- Or manually restart it
### Current Configuration
**Frontend** (`.env.local`):
```env
VITE_CLERK_PUBLISHABLE_KEY=pk_test_YWJvdmUtZmxvdW5kZXItOTEuY2xlcmsuYWNjb3VudHMuZGV2JA
```
✅ This is configured correctly
**Backend** (`server/.env`):
```env
CLERK_SECRET_KEY="sk_test_placeholder"
```
❌ This needs to be updated with your real secret key
### How to Find Your Keys
1. Visit: https://dashboard.clerk.com/last-active?path=api-keys
2. You'll see two keys:
- **Publishable Key** (pk_test_...) - Already configured in frontend ✅
- **Secret Key** (sk_test_...) - Needs to be added to backend ❌
### Security Note
⚠️ **Never commit your secret key to version control!**
The `.env` file is already in `.gitignore`, but always double-check before committing.
### Testing After Setup
Once you've added the correct secret key:
1. The server will restart automatically
2. Try uploading a photo in the report form
3. You should see successful uploads instead of 401 errors
### Verification
You can verify the setup is working by checking the server logs:
```
Auth middleware - Authorization header: present
Auth middleware - Token extracted, length: XXX
Auth middleware - Session verified for user: user_XXXXX
```
If you see these logs, authentication is working correctly!