Skip to content

An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.

fix: encrypt resend API key in instance settings

peaklabs-dev5087906b24eb
diff --git a/database/migrations/2024_12_13_103007_encrypt_resend_api_key_in_instance_settings.php b/database/migrations/2024_12_13_103007_encrypt_resend_api_key_in_instance_settings.php
new file mode 100644
index 0000000000..33e18e25a7
--- /dev/null
+++ b/database/migrations/2024_12_13_103007_encrypt_resend_api_key_in_instance_settings.php
@@ -0,0 +1,56 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Crypt;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+ /**
+ * Run the migrations.
+ */
+ public function up(): void
+ {
+ if (DB::table('instance_settings')->exists()) {
+ Schema::table('instance_settings', function (Blueprint $table) {
+ $table->text('resend_api_key')->nullable()->change();
+ });
+
+ $settings = DB::table('instance_settings')->get();
+ foreach ($settings as $setting) {
+ try {
+ DB::table('instance_settings')->where('id', $setting->id)->update([
+ 'resend_api_key' => $setting->resend_api_key ? Crypt::encryptString($setting->resend_api_key) : null,
+ ]);
+ } catch (Exception $e) {
+ \Log::error('Error encrypting resend_api_key: '.$e->getMessage());
+ }
+ }
+ }
+ }
+
+ /**
+ * Reverse the migrations.
+ */
+ public function down(): void
+ {
+ Schema::table('instance_settings', function (Blueprint $table) {
+ $table->text('resend_api_key')->nullable()->change();
+ });
+
+ if (DB::table('instance_settings')->exists()) {
+ $settings = DB::table('instance_settings')->get();
+ foreach ($settings as $setting) {
+ try {
+ DB::table('instance_settings')->where('id', $setting->id)->update([
+ 'resend_api_key' => $setting->resend_api_key ? Crypt::decryptString($setting->resend_api_key) : null,
+ ]);
+ } catch (Exception $e) {
+ \Log::error('Error decrypting resend_api_key: '.$e->getMessage());
+ }
+ }
+ }
+ }
+};