← back to Designer Wallcoverings
DW-Agents/dw-agents/fix-last-3-agents.sh
66 lines
#!/bin/bash
# Fix the last 3 agents that need Google OAuth
echo "🔧 Fixing last 3 agents to use Google OAuth..."
# Agent 1: Legal Team
echo ""
echo "1️⃣ Fixing legal-agent..."
FILE="/root/DW-Agents/agent-legal-team/legal-agent.ts"
# Remove old login routes (lines 234-410 approximately)
sed -i '234,410d' "$FILE"
echo " ✓ Removed old login routes"
# Agent 2: Purchasing Office
echo ""
echo "2️⃣ Fixing purchasing-office-agent..."
FILE="/root/DW-Agents/agent-purchasing-office/purchasing-office-agent.ts"
# Add import at top
sed -i '1i import { requireGlobalAuth } from '\''../shared-global-auth'\'';' "$FILE"
sed -i '1i import cookieParser from '\''cookie-parser'\'';' "$FILE"
# Remove custom requireAuth function (around line 195-200)
sed -i '/^const requireAuth = /,/^};$/d' "$FILE"
# Add global auth middleware after app creation
sed -i '/const app = express/a \\napp.use(cookieParser());\napp.use(requireGlobalAuth);\n' "$FILE"
# Remove requireAuth from all route definitions
sed -i 's/, requireAuth,/, /g' "$FILE"
sed -i 's/, requireAuth / /g' "$FILE"
echo " ✓ Updated imports and middleware"
echo " ✓ Removed custom requireAuth"
echo " ✓ Cleaned up routes"
# Agent 3: Trend Research
echo ""
echo "3️⃣ Fixing trend-research-agent..."
FILE="/root/DW-Agents/agent-trend-research/trend-research-agent.ts"
# Check what auth system it uses
if grep -q "shared-auth" "$FILE"; then
# Replace shared-auth import
sed -i "s|from './shared-auth'|from '../shared-global-auth'|g" "$FILE"
sed -i "s|requireAuth as ssoAuth|requireGlobalAuth|g" "$FILE"
sed -i "/setSSOToken\|SSO_TOKEN/d" "$FILE"
echo " ✓ Updated imports"
elif grep -q "const requireAuth" "$FILE"; then
# Has custom auth
sed -i '1i import { requireGlobalAuth } from '\''../shared-global-auth'\'';' "$FILE"
sed -i '1i import cookieParser from '\''cookie-parser'\'';' "$FILE"
sed -i '/^const requireAuth/,/^};$/d' "$FILE"
sed -i '/const app = express/a \\napp.use(cookieParser());\napp.use(requireGlobalAuth);\n' "$FILE"
sed -i 's/, requireAuth,/, /g' "$FILE"
sed -i 's/, requireAuth / /g' "$FILE"
echo " ✓ Replaced custom auth"
else
echo " ⚠️ Unknown auth system, needs manual review"
fi
echo ""
echo "✅ All 3 agents updated!"
echo ""
echo "📝 Next: Restart agents with pm2 restart dw-legal-team dw-purchasing-office dw-trend-research"