From 30e64a590e25aa1b088501f51522f47c286465b6 Mon Sep 17 00:00:00 2001 From: Alexander Borg Date: Sat, 13 Sep 2025 09:12:01 +0200 Subject: [PATCH] Fix jwt-token --- scripts/create-tenant-db.sh | 58 +++++++++++++++++++++++++++++++++++++ scripts/create-tenant.sh | 35 ++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 scripts/create-tenant-db.sh create mode 100644 scripts/create-tenant.sh diff --git a/scripts/create-tenant-db.sh b/scripts/create-tenant-db.sh new file mode 100644 index 0000000..657a453 --- /dev/null +++ b/scripts/create-tenant-db.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +# Direct Database Tenant Creation +# For when you need to create tenants via database + +TENANT_NAME="${1:-Example Corp}" +TENANT_SLUG="${2:-example}" + +echo "Creating tenant in database: $TENANT_NAME" + +# Execute in backend container +docker exec -it drone-detection-backend node -e " +const { Tenant, User } = require('./models'); + +async function createTenant() { + try { + // Create the tenant + const tenant = await Tenant.create({ + name: '$TENANT_NAME', + slug: '$TENANT_SLUG', + subscription_type: 'basic', + is_active: true, + auth_provider: 'local', + features: { + max_devices: 50, + max_users: 10, + api_rate_limit: 5000, + data_retention_days: 365, + features: ['basic_detection', 'alerts', 'dashboard', 'analytics'] + }, + admin_email: 'admin@$TENANT_SLUG.com' + }); + + console.log('✅ Tenant created:', tenant.toJSON()); + + // Create default admin user for this tenant + const adminUser = await User.create({ + username: 'admin', + email: 'admin@$TENANT_SLUG.com', + password: 'admin123', // Will be hashed automatically + role: 'admin', + tenant_id: tenant.id, + is_active: true + }); + + console.log('✅ Admin user created for tenant'); + console.log('🌐 Tenant URL: https://$TENANT_SLUG.dev.uggla.uamils.com'); + console.log('🔑 Login: admin / admin123'); + + } catch (error) { + console.error('❌ Error creating tenant:', error.message); + } finally { + process.exit(0); + } +} + +createTenant(); +" diff --git a/scripts/create-tenant.sh b/scripts/create-tenant.sh new file mode 100644 index 0000000..7b29158 --- /dev/null +++ b/scripts/create-tenant.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +# Quick Tenant Setup Script +# Creates a new tenant with basic configuration + +TENANT_NAME="${1:-Example Corp}" +TENANT_SLUG="${2:-example}" +SUBSCRIPTION_TYPE="${3:-basic}" +AUTH_PROVIDER="${4:-local}" + +echo "Creating tenant: $TENANT_NAME (slug: $TENANT_SLUG)" + +# Create tenant via API +curl -X POST https://management.dev.uggla.uamils.com/api/tenants \ + -H "Content-Type: application/json" \ + -H "Authorization: Bearer YOUR_ADMIN_JWT_TOKEN" \ + -d "{ + \"name\": \"$TENANT_NAME\", + \"slug\": \"$TENANT_SLUG\", + \"subscription_type\": \"$SUBSCRIPTION_TYPE\", + \"auth_provider\": \"$AUTH_PROVIDER\", + \"admin_email\": \"admin@$TENANT_SLUG.com\", + \"features\": { + \"max_devices\": 50, + \"max_users\": 10, + \"api_rate_limit\": 5000, + \"data_retention_days\": 365, + \"features\": [\"basic_detection\", \"alerts\", \"dashboard\", \"analytics\"] + } + }" + +echo "" +echo "✅ Tenant created!" +echo "🌐 Access URL: https://$TENANT_SLUG.dev.uggla.uamils.com" +echo "🔑 Users can now register/login at that URL"