Add schema cache fallback for service account JSON

- Add fallback RPC method when PostgREST schema cache fails
- Save service account JSON separately via raw SQL
- Show warning message if manual save needed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
dwindown
2025-12-23 10:52:00 +07:00
parent 00e6ef17d6
commit 7c2a084b3e
2 changed files with 44 additions and 1 deletions

View File

@@ -116,7 +116,40 @@ export function IntegrasiTab() {
.update(platformPayload)
.eq('id', settings.id);
if (platformError) throw platformError;
if (platformError) {
// If schema cache error, try saving service account JSON separately via raw SQL
if (platformError.code === 'PGRST204' && settings.integration_google_service_account_json) {
console.log('Schema cache error, using fallback RPC method');
const { error: rpcError } = await supabase.rpc('exec_sql', {
sql: `UPDATE platform_settings SET google_service_account_json = '${settings.integration_google_service_account_json.replace(/'/g, "''")}'::jsonb WHERE id = '${settings.id}'`
});
if (rpcError) {
// Save other fields without the problematic column
const { error: retryError } = await supabase
.from('platform_settings')
.update({
integration_n8n_base_url: settings.integration_n8n_base_url,
integration_whatsapp_number: settings.integration_whatsapp_number,
integration_whatsapp_url: settings.integration_whatsapp_url,
integration_google_calendar_id: settings.integration_google_calendar_id,
integration_email_provider: settings.integration_email_provider,
integration_email_api_base_url: settings.integration_email_api_base_url,
integration_privacy_url: settings.integration_privacy_url,
integration_terms_url: settings.integration_terms_url,
integration_n8n_test_mode: settings.integration_n8n_test_mode,
})
.eq('id', settings.id);
if (retryError) throw retryError;
toast({ title: 'Peringatan', description: 'Pengaturan disimpan tapi Service Account JSON perlu disimpan manual. Hubungi admin.' });
} else {
toast({ title: 'Berhasil', description: 'Service Account JSON disimpan via RPC' });
}
} else {
throw platformError;
}
}
}
// Save email provider settings to notification_settings