-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsandbox-endpoints.ts
More file actions
50 lines (40 loc) · 1.85 KB
/
Copy pathsandbox-endpoints.ts
File metadata and controls
50 lines (40 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { Request, Response, Express } from 'express';
import { createSandboxToken } from './demo-routes';
// Admin authentication middleware - requires actual authenticated session
const requireAdminAuth = (req: Request, res: Response, next: any) => {
// Check if user is authenticated via session (Replit OIDC)
if (req.isAuthenticated && req.isAuthenticated()) {
return next();
}
return res.status(403).json({ error: 'Admin access required. Please authenticate via Replit OIDC.' });
};
export function setupSandboxEndpoints(app: Express) {
// Create sandbox token for admin testing (POST) - REQUIRES ADMIN AUTH
app.post('/api/demo/sandbox-token', requireAdminAuth, async (req: Request, res: Response) => {
try {
const { slackUserId, userName = 'Sandbox User' } = req.body;
if (!slackUserId) {
return res.status(400).json({ error: 'slackUserId is required' });
}
const token = createSandboxToken(slackUserId, userName);
res.json({ token, slackUserId, userName });
} catch (error) {
console.error('Error creating sandbox token:', error);
res.status(500).json({ error: 'Failed to create sandbox token' });
}
});
// Get sandbox token for admin testing (GET) - REQUIRES ADMIN AUTH
app.get('/api/demo/sandbox-token', requireAdminAuth, async (req: Request, res: Response) => {
try {
const { slackUserId, userName = 'Sandbox User' } = req.query;
if (!slackUserId) {
return res.status(400).json({ error: 'slackUserId is required' });
}
const token = createSandboxToken(slackUserId as string, userName as string);
res.json({ token, slackUserId, userName });
} catch (error) {
console.error('Error creating sandbox token:', error);
res.status(500).json({ error: 'Failed to create sandbox token' });
}
});
}