mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 08:11:13 -05:00
Add edge function logging
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user