#!/bin/bash # Quick deployment script for authentication fixes # Run from /data/app/igny8 directory set -e # Exit on error echo "🚀 Starting authentication fix deployment..." echo "" # Check we're in the right directory if [ ! -f "backend/manage.py" ]; then echo "❌ Error: Must run from /data/app/igny8 directory" exit 1 fi # Step 1: Install backend dependencies echo "📦 Step 1/7: Installing backend dependencies..." cd backend pip install django-redis>=5.4.0 --quiet cd .. echo "✅ Dependencies installed" echo "" # Step 2: Create and run migrations echo "🗄️ Step 2/7: Running database migrations..." cd backend python manage.py makemigrations --noinput python manage.py migrate --noinput cd .. echo "✅ Migrations completed" echo "" # Step 3: Verify Redis echo "🔍 Step 3/7: Verifying Redis connection..." if docker exec redis redis-cli ping > /dev/null 2>&1; then echo "✅ Redis is running" else echo "⚠️ Warning: Redis not responding. Starting Redis..." cd /data/app docker-compose -f docker-compose.yml up -d redis sleep 3 cd /data/app/igny8 fi echo "" # Step 4: Backup and replace api.ts echo "📝 Step 4/7: Updating frontend API service..." cd frontend/src/services if [ -f "api.ts" ]; then cp api.ts "api-old-$(date +%Y%m%d-%H%M%S).ts" echo " Backed up old api.ts" fi if [ -f "api-new.ts" ]; then mv api-new.ts api.ts echo "✅ API service updated" else echo "⚠️ Warning: api-new.ts not found, skipping" fi cd ../../.. echo "" # Step 5: Restart backend echo "🔄 Step 5/7: Restarting backend service..." docker-compose -f docker-compose.app.yml restart igny8_backend echo " Waiting for backend to be healthy..." sleep 5 if docker-compose -f docker-compose.app.yml ps igny8_backend | grep -q "Up"; then echo "✅ Backend restarted successfully" else echo "⚠️ Warning: Backend may not be healthy. Check: docker-compose -f docker-compose.app.yml ps" fi echo "" # Step 6: Restart frontend echo "🔄 Step 6/7: Restarting frontend service..." docker-compose -f docker-compose.app.yml restart igny8_frontend echo " Waiting for frontend to start..." sleep 3 if docker-compose -f docker-compose.app.yml ps igny8_frontend | grep -q "Up"; then echo "✅ Frontend restarted successfully" else echo "⚠️ Warning: Frontend may not be healthy. Check: docker-compose -f docker-compose.app.yml ps" fi echo "" # Step 7: Quick health check echo "🏥 Step 7/7: Running health checks..." echo "" echo "Backend health:" if curl -sf http://localhost:8011/api/v1/system/status/ > /dev/null 2>&1; then echo " ✅ Backend API responding" else echo " ⚠️ Backend API not responding at http://localhost:8011" fi echo "" echo "Frontend health:" if curl -sf http://localhost:8021 > /dev/null 2>&1; then echo " ✅ Frontend responding" else echo " ⚠️ Frontend not responding at http://localhost:8021" fi echo "" echo "Redis health:" REDIS_KEYS=$(docker exec redis redis-cli DBSIZE 2>/dev/null | grep -o '[0-9]*' || echo "0") echo " ✅ Redis has $REDIS_KEYS keys" echo "" echo "Database check:" cd backend TOKEN_COUNT=$(python manage.py shell -c "from igny8_core.auth.models_refresh_token import RefreshToken; print(RefreshToken.objects.count())" 2>/dev/null || echo "0") echo " ✅ RefreshToken model working ($TOKEN_COUNT tokens in DB)" cd .. echo "" echo "=========================================" echo "🎉 Deployment completed!" echo "=========================================" echo "" echo "Next steps:" echo "1. Test login with remember-me checkbox" echo "2. Verify no logout on 403 errors" echo "3. Test multi-tab behavior" echo "4. Monitor logs for issues" echo "" echo "📊 View logs:" echo " Backend: docker logs igny8_backend -f" echo " Frontend: docker logs igny8_frontend -f" echo "" echo "📖 Documentation:" echo " - AUTHENTICATION-FIX-IMPLEMENTATION.md" echo " - AUTHENTICATION-FIX-DEPLOYMENT.md" echo " - AUTHENTICATION-AUDIT-REPORT.md" echo "" echo "⚠️ IMPORTANT: Complete remaining manual steps from AUTHENTICATION-FIX-DEPLOYMENT.md:" echo " - Update authStore.ts to remove localStorage.setItem('access_token')" echo " - Add remember-me checkbox to login form" echo " - Test all scenarios before marking as complete" echo ""