Improve error handling and authentication for uploads and notifications

Refactor PhotoUpload component to fetch session token before polling, enhance error handling in NotificationService and versioningHelpers with `instanceof Error` checks, and add comprehensive validation for request body fields in the create-novu-subscriber Supabase function.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 8d708ff6-09f1-4b67-8edc-de3fcb2349b3
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
This commit is contained in:
pac7
2025-10-07 14:55:35 +00:00
parent f4020969d8
commit 88ed3207c4
5 changed files with 138 additions and 6 deletions

View File

@@ -148,16 +148,25 @@ export function PhotoUpload({
throw new Error('Direct upload to Cloudflare failed');
}
// Fetch session token once before polling
const sessionData = await supabase.auth.getSession();
const accessToken = sessionData.data.session?.access_token;
if (!accessToken) {
revokeObjectUrl(previewUrl);
throw new Error('Authentication required for upload');
}
const maxAttempts = 60;
let attempts = 0;
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL || 'https://ydvtmnrszybqnbcqbdcy.supabase.co';
while (attempts < maxAttempts) {
try {
const supabaseUrl = import.meta.env.VITE_SUPABASE_URL || 'https://ydvtmnrszybqnbcqbdcy.supabase.co';
const response = await fetch(`${supabaseUrl}/functions/v1/upload-image?id=${encodeURIComponent(id)}`, {
method: 'GET',
headers: {
'Authorization': `Bearer ${(await supabase.auth.getSession()).data.session?.access_token}`,
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
}
});