Fix jwt-token
This commit is contained in:
58
scripts/create-tenant-db.sh
Normal file
58
scripts/create-tenant-db.sh
Normal file
@@ -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();
|
||||||
|
"
|
||||||
35
scripts/create-tenant.sh
Normal file
35
scripts/create-tenant.sh
Normal file
@@ -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"
|
||||||
Reference in New Issue
Block a user