Add edge function logging

This commit is contained in:
gpt-engineer-app[bot]
2025-10-21 11:56:07 +00:00
parent 0f7bb7f928
commit d886343398
7 changed files with 157 additions and 65 deletions

View File

@@ -1,5 +1,6 @@
import { serve } from "https://deno.land/std@0.168.0/http/server.ts"
import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'
import { edgeLogger } from '../_shared/logger.ts'
// Environment-aware CORS configuration
const getAllowedOrigin = (requestOrigin: string | null): string | null => {
@@ -72,9 +73,9 @@ serve(async (req) => {
const requestOrigin = req.headers.get('origin');
const allowedOrigin = getAllowedOrigin(requestOrigin);
// Check if this is a CORS request with a disallowed origin
// Check if this is a CORS request with a disallowed origin
if (requestOrigin && !allowedOrigin) {
console.error(`[CORS] Request rejected for disallowed origin: ${requestOrigin}`);
edgeLogger.warn('CORS request rejected', { action: 'cors_validation', origin: requestOrigin });
return new Response(
JSON.stringify({
error: 'Origin not allowed',
@@ -124,7 +125,7 @@ serve(async (req) => {
const { data: { user }, error: authError } = await supabase.auth.getUser()
if (authError || !user) {
console.error('Auth verification failed:', authError)
edgeLogger.error('Auth verification failed', { action: 'delete_auth', error: authError?.message })
return new Response(
JSON.stringify({
error: 'Invalid authentication',
@@ -145,7 +146,7 @@ serve(async (req) => {
.single()
if (profileError || !profile) {
console.error('Failed to fetch user profile:', profileError)
edgeLogger.error('Failed to fetch user profile', { action: 'delete_profile_check', userId: user.id })
return new Response(
JSON.stringify({
error: 'User profile not found',