auth splitting

This commit is contained in:
overcuriousity
2025-07-26 14:07:18 +02:00
parent a4f4e03cba
commit d2fdeccce3
13 changed files with 87 additions and 69 deletions

View File

@@ -139,23 +139,19 @@ async function uploadToLocal(file: File, userType: string): Promise<UploadResult
}
}
// POST endpoint for file uploads
export const POST: APIRoute = async ({ request }) => {
return await handleAPIRequest(async () => {
// Authentication check
const authResult = await withAPIAuth(request);
const authResult = await withAPIAuth(request, 'contributions');
if (authResult.authRequired && !authResult.authenticated) {
return apiError.unauthorized();
}
const userEmail = authResult.session?.email || 'anonymous@example.com';
const userEmail = authResult.session?.email || 'anon@anon.anon';
// Rate limiting
if (!checkUploadRateLimit(userEmail)) {
return apiError.rateLimit('Upload rate limit exceeded. Please wait before uploading again.');
}
// Parse multipart form data
let formData;
try {
formData = await request.formData();