Files
dwroller/database/routes/sessionRoutes.js
T
alexandClaude Sonnet 4.6 43d0becdf6 Fix missing DB table, rules column, GM endpoints, and logout
- Add rules table to createTables() with auto-seed from rules-database.json
- Fix page_num → page column mapping in rulesRoutes.js
- Fix INSERT column names in rulesHelpers.create() and stagingHelpers
- Add POST /api/sessions/logout endpoint
- Add GM endpoints: set-xp, set-xp-spent, set-rp, set-renown,
  add-or-update, reset-password, DELETE gm/delete/:name
- All GM endpoints require x-gm-secret header (403 otherwise)

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
2026-03-01 18:08:30 +01:00

52 lines
1.5 KiB
JavaScript

const express = require('express');
const { logToFile } = require('../mariadb');
const router = express.Router();
// Simple session validation endpoint
router.post('/validate', async (req, res) => {
try {
const { sessionId } = req.body;
if (!sessionId) {
logToFile('SESSION: Validate missing sessionId');
return res.status(400).json({ error: 'sessionId required' });
}
// Extract player name from session ID (simple format: session_playername_timestamp)
const match = sessionId.match(/^session_([^_]+)_\d+$/);
if (!match) {
logToFile('SESSION: Invalid session format', sessionId);
return res.status(401).json({ error: 'Invalid session format' });
}
const playerName = match[1];
logToFile('SESSION: Session validation successful', playerName);
res.json({
valid: true,
playerName
});
} catch (error) {
console.error('Session validation error:', error);
logToFile('SESSION: Failed to validate session', error);
res.status(500).json({ error: String(error) });
}
});
// Logout endpoint
router.post('/logout', async (req, res) => {
try {
const { sessionId } = req.body;
if (sessionId) {
logToFile('SESSION: Logout', sessionId);
}
res.json({ success: true });
} catch (error) {
logToFile('SESSION: Logout error', error);
res.status(500).json({ error: String(error) });
}
});
console.log('Session routes registered (simple validation)');
module.exports = router;