feat: improve file upload authentication and error handling

- Add better error messages for authentication failures
- Display warning in ReportForm when user is not signed in
- Update documentation with authentication requirements
- Improve error handling in reportService.uploadPhoto()

This helps users understand they need to be signed in to upload photos.
This commit is contained in:
2025-11-16 19:21:47 +00:00
parent 6d30405428
commit 18e1e03bfc
3 changed files with 55 additions and 2 deletions

View File

@@ -100,14 +100,30 @@ Files are accessible at: `http://localhost:3005/uploads/{filename}`
### 1. Upload Photo
**Important**: The user must be signed in with Clerk to upload photos. The frontend automatically includes the Clerk session token in the Authorization header.
```typescript
// Frontend usage (with Clerk authentication)
const formData = new FormData();
formData.append('photo', file);
// The reportService automatically includes the auth token
const { url, exifData } = await reportService.uploadPhoto(file);
```
**Manual API call** (for testing):
```typescript
const formData = new FormData();
formData.append('photo', file);
// Get Clerk token (in a Clerk-authenticated component)
const { getToken } = useAuth();
const token = await getToken();
const response = await fetch('/api/reports/upload', {
method: 'POST',
headers: {
'Authorization': `Bearer ${clerkToken}`
'Authorization': `Bearer ${token}`
},
body: formData
});