Spaces:
Runtime error
Runtime error
9 issues fixed
Browse files- gateway.ts +28 -0
gateway.ts
CHANGED
|
@@ -130,6 +130,34 @@ app.post('/api/auth/register', async (req, res) => {
|
|
| 130 |
}
|
| 131 |
});
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
// Verify token endpoint
|
| 134 |
app.get('/api/auth/verify', authenticateToken, (req, res) => {
|
| 135 |
res.json({ valid: true, user: (req as any).user });
|
|
|
|
| 130 |
}
|
| 131 |
});
|
| 132 |
|
| 133 |
+
// Logout endpoint - proxy to backend and clear server-side session
|
| 134 |
+
app.post('/api/auth/logout', apiLimiter, authenticateToken, async (req, res) => {
|
| 135 |
+
try {
|
| 136 |
+
const user = (req as any).user;
|
| 137 |
+
console.log('🚪 Logout request for:', user?.username);
|
| 138 |
+
|
| 139 |
+
// Forward to backend to clear conversation history
|
| 140 |
+
await axios.post(`${BACKEND_URL}/api/auth/logout`, {
|
| 141 |
+
user: { username: user?.username, name: user?.name }
|
| 142 |
+
}, {
|
| 143 |
+
headers: {
|
| 144 |
+
'Content-Type': 'application/json',
|
| 145 |
+
...(HF_TOKEN && { 'Authorization': `Bearer ${HF_TOKEN}` }),
|
| 146 |
+
...(BACKEND_API_SECRET && { 'X-API-Key': BACKEND_API_SECRET })
|
| 147 |
+
},
|
| 148 |
+
timeout: 5000
|
| 149 |
+
}).catch((err) => {
|
| 150 |
+
// Non-fatal: backend may be down, still complete client-side logout
|
| 151 |
+
console.warn('⚠️ Backend logout failed (non-fatal):', err.message);
|
| 152 |
+
});
|
| 153 |
+
|
| 154 |
+
res.json({ message: 'Logged out successfully' });
|
| 155 |
+
} catch (error: any) {
|
| 156 |
+
console.error('Logout error:', error.message);
|
| 157 |
+
res.status(500).json({ error: 'Internal server error' });
|
| 158 |
+
}
|
| 159 |
+
});
|
| 160 |
+
|
| 161 |
// Verify token endpoint
|
| 162 |
app.get('/api/auth/verify', authenticateToken, (req, res) => {
|
| 163 |
res.json({ valid: true, user: (req as any).user });
|