messy logout fixing
This commit is contained in:
141
scripts/deploy-auth-fix.sh
Normal file
141
scripts/deploy-auth-fix.sh
Normal file
@@ -0,0 +1,141 @@
|
||||
#!/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 ""
|
||||
99
scripts/deploy-logout-debugging.sh
Normal file
99
scripts/deploy-logout-debugging.sh
Normal file
@@ -0,0 +1,99 @@
|
||||
#!/bin/bash
|
||||
# Deploy Logout Debugging System
|
||||
# Run this script to deploy all backend and frontend changes
|
||||
|
||||
set -e # Exit on error
|
||||
|
||||
echo "======================================"
|
||||
echo "Deploying Logout Debugging System"
|
||||
echo "======================================"
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Check if we're in the right directory
|
||||
if [ ! -d "backend" ] || [ ! -d "frontend" ]; then
|
||||
echo -e "${RED}Error: Must run from project root directory${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Backend deployment
|
||||
echo -e "\n${GREEN}[1/4] Deploying Backend Changes...${NC}"
|
||||
cd backend
|
||||
|
||||
echo "Running migrations..."
|
||||
python manage.py migrate
|
||||
|
||||
echo "Checking for migration errors..."
|
||||
python manage.py check
|
||||
|
||||
echo -e "${GREEN}✓ Backend migrations complete${NC}"
|
||||
|
||||
# Frontend build
|
||||
echo -e "\n${GREEN}[2/4] Building Frontend...${NC}"
|
||||
cd ../frontend
|
||||
|
||||
echo "Installing dependencies..."
|
||||
npm install --silent
|
||||
|
||||
echo "Building production bundle..."
|
||||
npm run build
|
||||
|
||||
echo -e "${GREEN}✓ Frontend build complete${NC}"
|
||||
|
||||
# Restart services
|
||||
echo -e "\n${GREEN}[3/4] Restarting Services...${NC}"
|
||||
|
||||
if command -v docker-compose &> /dev/null; then
|
||||
echo "Restarting Docker containers..."
|
||||
docker-compose restart backend frontend
|
||||
echo -e "${GREEN}✓ Docker services restarted${NC}"
|
||||
elif systemctl is-active --quiet gunicorn; then
|
||||
echo "Restarting systemd services..."
|
||||
sudo systemctl restart gunicorn
|
||||
sudo systemctl restart celery
|
||||
echo -e "${GREEN}✓ Systemd services restarted${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}Warning: Could not detect service manager${NC}"
|
||||
echo "Please restart your backend and frontend services manually"
|
||||
fi
|
||||
|
||||
# Verification
|
||||
echo -e "\n${GREEN}[4/4] Verifying Deployment...${NC}"
|
||||
|
||||
echo "Checking backend API..."
|
||||
BACKEND_URL="${BACKEND_URL:-http://localhost:8000}"
|
||||
if curl -s "${BACKEND_URL}/v1/auth/logout-event/" -X POST -H "Content-Type: application/json" -d '{}' > /dev/null; then
|
||||
echo -e "${GREEN}✓ Backend logout-event endpoint responding${NC}"
|
||||
else
|
||||
echo -e "${YELLOW}⚠ Backend endpoint check failed (may need authentication)${NC}"
|
||||
fi
|
||||
|
||||
echo "Checking frontend build..."
|
||||
if [ -f "frontend/dist/index.html" ]; then
|
||||
echo -e "${GREEN}✓ Frontend dist/index.html exists${NC}"
|
||||
else
|
||||
echo -e "${RED}✗ Frontend build may have failed${NC}"
|
||||
fi
|
||||
|
||||
# Final instructions
|
||||
echo -e "\n${GREEN}======================================"
|
||||
echo "✓ Deployment Complete!"
|
||||
echo "======================================${NC}"
|
||||
|
||||
echo -e "\n${YELLOW}Next Steps:${NC}"
|
||||
echo "1. Open browser DevTools (F12)"
|
||||
echo "2. Go to Console tab"
|
||||
echo "3. Look for: '[TokenMonitor] Starting token expiry monitoring...'"
|
||||
echo "4. Login with 'Remember me' checked"
|
||||
echo "5. Wait 25+ minutes to capture logout event"
|
||||
echo ""
|
||||
echo "Debug Panel: Press Ctrl+Shift+D to open"
|
||||
echo "Full Guide: See LOGOUT-DEBUGGING-DEPLOYMENT.md"
|
||||
echo ""
|
||||
echo -e "${YELLOW}Monitor console logs every 30 seconds for token status${NC}"
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user