← back to Designer Wallcoverings
DW-Agents/dw-agents/integrate-global-auth.md
170 lines
# Integrating Global Auth into All DW-Agents
## Status
✅ **Auth Server Running**: http://45.61.58.125:9999
✅ **Admins Configured**: SteveAbramsDesigns@gmail.com, Browntwn@gmail.com
✅ **Shared Middleware Created**: `/root/DW-Agents/shared-global-auth.ts`
⚠️ **Agents Not Yet Protected** - Need to integrate into each agent
## Quick Integration (2 Steps per Agent)
### Step 1: Import the middleware
Add to the top of each agent's main file:
```typescript
import { requireGlobalAuth } from '../shared-global-auth';
import cookieParser from 'cookie-parser';
```
### Step 2: Protect all routes
Replace the old auth middleware with global auth:
```typescript
// Add cookie parser if not already present
app.use(cookieParser());
// Protect ALL routes (add this BEFORE any route handlers)
app.use(requireGlobalAuth);
// Now all your routes are protected
app.get('/', (req, res) => {
// User is authenticated via Google OAuth
// Access user info: req.authUser.email
res.send(...);
});
```
## Example: Master Hub Integration
**File**: `/root/DW-Agents/master-hub.ts`
**Before**:
```typescript
const requireAuth = (req: Request, res: Response, next: any) => {
if (req.session.authenticated) return next();
res.redirect('/login');
};
app.get('/', requireAuth, (req, res) => {
// ...
});
```
**After**:
```typescript
import { requireGlobalAuth } from './shared-global-auth';
import cookieParser from 'cookie-parser';
app.use(cookieParser());
app.use(requireGlobalAuth); // Protects ALL routes
app.get('/', (req, res) => {
// User automatically authenticated
const userEmail = req.authUser?.email;
// ...
});
```
## Agents to Update
### Executive Dashboards (Priority 1)
- [ ] Master Hub (port 9893)
- [ ] CEO Dashboard (port 7121)
- [ ] CFO Dashboard (port 7122)
- [ ] COO Dashboard (port 7124)
- [ ] VP Operations (port 7123)
### Core Operations (Priority 2)
- [ ] Security Agent (port 9892)
- [ ] Needs Attention (port 9886)
- [ ] Legal Team (port 9878)
- [ ] Accounting (port 9882)
- [ ] Shopify Store (port 7238)
### Support Agents (Priority 3)
- [ ] Marketing (port 9881)
- [ ] Purchasing (port 9880)
- [ ] Digital Samples (port 9879)
- [ ] Trend Research (port 9883)
- [ ] Skills Manager (port 9894)
- [ ] Task Orchestrator (port 9900)
- [ ] Zendesk Chat (port 9884)
- [ ] All others...
## Automated Integration Script
I can create a script that:
1. Backs up all agent files
2. Adds the global auth import
3. Replaces old auth with new middleware
4. Restarts all agents
**Want me to run the automated integration now?** (Yes/No)
## Manual Integration Steps
If you prefer to integrate manually:
1. For each agent file:
```bash
nano /root/DW-Agents/agent-name/agent-file.ts
```
2. Add imports at top:
```typescript
import { requireGlobalAuth } from '../shared-global-auth';
import cookieParser from 'cookie-parser';
```
3. Remove old session/auth middleware
4. Add before routes:
```typescript
app.use(cookieParser());
app.use(requireGlobalAuth);
```
5. Remove old `/login` and `/logout` routes (handled by auth server)
6. Restart agent:
```bash
pm2 restart agent-name
```
## Testing
After integration:
1. Visit any agent URL (e.g., http://45.61.58.125:9893/)
2. Should redirect to: http://45.61.58.125:9999/login
3. Click "Sign in with Google"
4. Accept terms
5. Redirected back to agent
6. All agents use same session!
## Benefits After Integration
✅ Single sign-on across all agents
✅ 4-hour session with SMS re-auth
✅ Security monitoring and logging
✅ Automatic blocked user protection
✅ Admin access control
✅ Session error tracking
✅ No more individual passwords per agent
## Current Status
**Auth Server**: ✅ Running (port 9999)
**Middleware**: ✅ Created (`shared-global-auth.ts`)
**Admins**: ✅ Configured (Steve & Browntwn)
**Agents**: ⚠️ Still using old auth (need integration)
**Ready to integrate?** Let me know if you want:
- A) Automated integration script (updates all agents)
- B) Manual integration (I'll guide you through each one)
- C) Start with just Master Hub as a test