Fix: Resolve edge function auth error

This commit is contained in:
gpt-engineer-app[bot]
2025-11-05 19:23:25 +00:00
parent 435ddf476b
commit bdd4e046f5

View File

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