diff --git a/supabase/functions/process-selective-approval/index.ts b/supabase/functions/process-selective-approval/index.ts index b6f303b9..97c97f1b 100644 --- a/supabase/functions/process-selective-approval/index.ts +++ b/supabase/functions/process-selective-approval/index.ts @@ -437,6 +437,7 @@ const approvalRateLimiter = rateLimiters.perUser(10); serve(withRateLimit(async (req) => { const tracking = startRequest(); // Start request tracking + let authenticatedUserId: string | undefined = undefined; // Declare outside try block for catch access if (req.method === 'OPTIONS') { return new Response(null, { headers: corsHeaders }); @@ -564,7 +565,7 @@ serve(withRateLimit(async (req) => { // (parks, rides, companies, ride_models) which have RLS policies // Security measures: User auth verified above, moderator role checked via RPC - const authenticatedUserId = user.id; + authenticatedUserId = user.id; // Create service role client for privileged operations (including role check) const supabase = createClient( @@ -1232,7 +1233,7 @@ serve(withRateLimit(async (req) => { edgeLogger.error('Approval process failed', { action: 'approval_process_error', error: errorMessage, - userId: authenticatedUserId, + userId: authenticatedUserId || 'unknown', requestId: tracking.requestId, duration });