Fix: Use account hash for Cloudflare avatars

This commit is contained in:
gpt-engineer-app[bot]
2025-10-12 00:19:04 +00:00
parent 8d5e235772
commit 5f8cb16453

View File

@@ -6,16 +6,16 @@ const corsHeaders = {
'Access-Control-Allow-Headers': 'authorization, x-client-info, apikey, content-type',
};
const CLOUDFLARE_ACCOUNT_ID = Deno.env.get('CLOUDFLARE_ACCOUNT_ID');
const CLOUDFLARE_ACCOUNT_HASH = Deno.env.get('CLOUDFLARE_ACCOUNT_HASH');
const CLOUDFLARE_API_TOKEN = Deno.env.get('CLOUDFLARE_IMAGES_API_TOKEN');
// Validate configuration at startup
if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_API_TOKEN) {
if (!CLOUDFLARE_ACCOUNT_HASH || !CLOUDFLARE_API_TOKEN) {
console.error('[OAuth Profile] Missing Cloudflare configuration:', {
hasAccountId: !!CLOUDFLARE_ACCOUNT_ID,
hasAccountHash: !!CLOUDFLARE_ACCOUNT_HASH,
hasApiToken: !!CLOUDFLARE_API_TOKEN,
});
console.error('[OAuth Profile] Please configure CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_IMAGES_API_TOKEN in Supabase Edge Function secrets');
console.error('[OAuth Profile] Please configure CLOUDFLARE_ACCOUNT_HASH and CLOUDFLARE_IMAGES_API_TOKEN in Supabase Edge Function secrets');
}
interface GoogleUserMetadata {
@@ -116,10 +116,10 @@ Deno.serve(async (req) => {
// Download and upload avatar to Cloudflare
if (avatarUrl) {
// Validate secrets before attempting upload
if (!CLOUDFLARE_ACCOUNT_ID || !CLOUDFLARE_API_TOKEN) {
if (!CLOUDFLARE_ACCOUNT_HASH || !CLOUDFLARE_API_TOKEN) {
console.warn('[OAuth Profile] Cloudflare secrets not configured, skipping avatar upload');
console.warn('[OAuth Profile] Missing:', {
accountId: !CLOUDFLARE_ACCOUNT_ID,
accountHash: !CLOUDFLARE_ACCOUNT_HASH,
apiToken: !CLOUDFLARE_API_TOKEN,
});
} else {
@@ -153,7 +153,7 @@ Deno.serve(async (req) => {
// Get upload URL from Cloudflare
const uploadUrlResponse = await fetch(
`https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_ID}/images/v2/direct_upload`,
`https://api.cloudflare.com/client/v4/accounts/${CLOUDFLARE_ACCOUNT_HASH}/images/v2/direct_upload`,
{
method: 'POST',
headers: {
@@ -188,7 +188,7 @@ Deno.serve(async (req) => {
if (result.success) {
cloudflareImageId = result.result.id;
cloudflareImageUrl = `https://imagedelivery.net/${CLOUDFLARE_ACCOUNT_ID}/${cloudflareImageId}/avatar`;
cloudflareImageUrl = `https://imagedelivery.net/${CLOUDFLARE_ACCOUNT_HASH}/${cloudflareImageId}/avatar`;
console.log('[OAuth Profile] Uploaded to Cloudflare:', { cloudflareImageId, cloudflareImageUrl });
} else {
throw new Error('Cloudflare upload failed');
@@ -196,7 +196,7 @@ Deno.serve(async (req) => {
} catch (error) {
console.error('[OAuth Profile] Avatar upload failed:', {
error: error.message,
accountId: CLOUDFLARE_ACCOUNT_ID,
accountHash: CLOUDFLARE_ACCOUNT_HASH,
hasToken: !!CLOUDFLARE_API_TOKEN,
avatarUrl,
});