21b1e79672
Test and Lint / backend-test (push) Successful in 1m11s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 2m6s
Version and Release / version-bump (push) Successful in 35s
Version and Release / trigger-drone (push) Successful in 3s
- Updated API interceptor to better handle gallery authentication - Fixed 401 error handling to prevent redirect loops on gallery pages - Improved token extraction logic for gallery API requests - Consolidated duplicate verifyGalleryAccess middleware - Added proper error handling in GalleryView component - Gallery authentication now properly distinguishes from admin routes The issue was caused by the API interceptor redirecting to admin login when gallery API calls failed with 401, even when users were already on gallery pages attempting to authenticate. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
36 lines
1001 B
JavaScript
36 lines
1001 B
JavaScript
const jwt = require('jsonwebtoken');
|
|
const { db } = require('../database/db');
|
|
const { formatBoolean } = require('../utils/dbCompat');
|
|
|
|
// Middleware to verify gallery access
|
|
async function verifyGalleryAccess(req, res, next) {
|
|
try {
|
|
const token = req.headers.authorization?.split(' ')[1];
|
|
if (!token) {
|
|
return res.status(401).json({ error: 'No token provided' });
|
|
}
|
|
|
|
const decoded = jwt.verify(token, process.env.JWT_SECRET);
|
|
const event = await db('events')
|
|
.where({
|
|
id: decoded.eventId,
|
|
is_active: formatBoolean(true),
|
|
is_archived: formatBoolean(false)
|
|
})
|
|
.first();
|
|
|
|
if (!event) {
|
|
return res.status(404).json({ error: 'Gallery not found or expired' });
|
|
}
|
|
|
|
req.event = event;
|
|
next();
|
|
} catch (error) {
|
|
console.error('Error verifying gallery access:', error);
|
|
res.status(401).json({ error: 'Invalid token', details: error.message });
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
verifyGalleryAccess
|
|
}; |