mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 05:11:14 -05:00
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:
@@ -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'
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user