Initial commit: Character sandbox with React+Express frontend/backend, SvelteKit foundation

This commit is contained in:
2026-06-30 16:57:28 +02:00
commit 85454f9737
48 changed files with 4662 additions and 0 deletions
+26
View File
@@ -0,0 +1,26 @@
import jwt from 'jsonwebtoken';
const JWT_SECRET = process.env.JWT_SECRET || 'sandbox-secret-key-change-in-production';
export function generateToken(userId) {
return jwt.sign({ userId }, JWT_SECRET, { expiresIn: '7d' });
}
export function authenticateToken(req, res, next) {
const authHeader = req.headers['authorization'];
const token = authHeader && authHeader.split(' ')[1];
if (!token) {
return res.status(401).json({ error: 'Authentication required' });
}
jwt.verify(token, JWT_SECRET, (err, decoded) => {
if (err) {
return res.status(403).json({ error: 'Invalid or expired token' });
}
req.userId = decoded.userId;
next();
});
}
export { JWT_SECRET };