fix(middleware): log ownership lookup failures; drop dead auth surface

ownership.js caught a lookup failure, returned 500 and logged nothing -- the
file had no logger import, so a failing ownership check was invisible in the
logs. Added logging matching photoAuth.js/permissions.js
({ error, stack } plus the relevant id), response behaviour unchanged. Fixed
both swallowed catches: requireEventOwnership, the reported one, and the
byte-identical requireProjectOwnership.

Also removes AdminAuthContext.updatePasswordChanged, now dead -- superseded
by the deliberate full-page reload in onSuccess, with zero callers left.
setMustChangePassword and mustChangePassword stay; nothing else orphaned.

Refs testplan REPORT.md B13, B16.
This commit is contained in:
Paul Nothaft
2026-09-02 09:43:10 +02:00
parent 103863cbab
commit 42ba8351c1
2 changed files with 11 additions and 18 deletions
+11 -2
View File
@@ -1,4 +1,5 @@
const { db } = require('../database/db'); const { db } = require('../database/db');
const logger = require('../utils/logger');
/** /**
* Middleware to enforce event ownership for non-super_admin users. * Middleware to enforce event ownership for non-super_admin users.
@@ -27,7 +28,10 @@ function requireEventOwnership(req, res, next) {
} }
next(); next();
}) })
.catch((_err) => { .catch((err) => {
logger.error('Event ownership check failed', {
eventId, adminId: req.admin.id, error: err.message, stack: err.stack,
});
res.status(500).json({ error: 'Failed to verify ownership' }); res.status(500).json({ error: 'Failed to verify ownership' });
}); });
} }
@@ -152,7 +156,12 @@ function requireProjectOwnership(req, res, next) {
if (!row) return res.status(404).json({ error: 'Project not found' }); if (!row) return res.status(404).json({ error: 'Project not found' });
next(); next();
}) })
.catch(() => res.status(500).json({ error: 'Failed to verify project ownership' })); .catch((err) => {
logger.error('Project ownership check failed', {
projectId, adminId: req.admin?.id, error: err.message, stack: err.stack,
});
res.status(500).json({ error: 'Failed to verify project ownership' });
});
} }
module.exports = { module.exports = {
@@ -12,7 +12,6 @@ interface AdminAuthContextType {
isLoading: boolean; isLoading: boolean;
error: string | null; error: string | null;
mustChangePassword: boolean; mustChangePassword: boolean;
updatePasswordChanged: () => void;
updateUserProfile: (updates: Partial<AdminUser>) => void; updateUserProfile: (updates: Partial<AdminUser>) => void;
} }
@@ -98,20 +97,6 @@ export const AdminAuthProvider: React.FC<AdminAuthProviderProps> = ({ children }
setMustChangePassword(false); setMustChangePassword(false);
}; };
const updatePasswordChanged = () => {
setMustChangePassword(false);
if (user) {
setUser({
...user,
mustChangePassword: false
});
sessionStorage.setItem('admin_user', JSON.stringify({
...user,
mustChangePassword: false
}));
}
};
const updateUserProfile = (updates: Partial<AdminUser>) => { const updateUserProfile = (updates: Partial<AdminUser>) => {
setUser((prev) => { setUser((prev) => {
if (!prev) { if (!prev) {
@@ -133,7 +118,6 @@ export const AdminAuthProvider: React.FC<AdminAuthProviderProps> = ({ children }
isLoading, isLoading,
error, error,
mustChangePassword, mustChangePassword,
updatePasswordChanged,
updateUserProfile, updateUserProfile,
}} }}
> >