This commit is contained in:
seb
2026-10-29 16:27:02 +01:00
parent 005b48ff66
commit 676a40d4fe
6 changed files with 50 additions and 16 deletions

View File

@@ -47,7 +47,7 @@ export function clearCachedCompanyUsers(companyId) {
}
}
function respondWithAuthPayload(res, req, status, body) {
async function respondWithAuthPayload(res, req, status, body) {
if (req.path === '/api/auth/me') {
return respondWithAuthenticatedUser(res, status, body);
}
@@ -85,7 +85,7 @@ export const authMiddleware = async (req, res, next) => {
const isDocs = req.path.startsWith('/docs') || req.path.startsWith('/api/docs');
if (!token) {
if (isDocs || isOAuthAuthorize) return next();
return respondWithAuthPayload(res, req, 401, { error: 'Unauthorized' });
return await respondWithAuthPayload(res, req, 401, { error: 'Unauthorized' });
}
try {
@@ -94,7 +94,7 @@ export const authMiddleware = async (req, res, next) => {
if (!Number.isInteger(authId) || authId <= 0) {
if (req.cookies.token) clearTokenCookie(res);
if (isDocs) return next();
return respondWithAuthPayload(res, req, 401, { error: 'Invalid token' });
return await respondWithAuthPayload(res, req, 401, { error: 'Invalid token' });
}
let user = getCachedUser(authId);
@@ -111,7 +111,7 @@ export const authMiddleware = async (req, res, next) => {
clearCachedUser(authId);
if (req.cookies.token) clearTokenCookie(res);
if (isDocs) return next();
return respondWithAuthPayload(res, req, 403, { error: 'User is no longer authorized' });
return await respondWithAuthPayload(res, req, 403, { error: 'User is no longer authorized' });
}
req.user = {
@@ -133,7 +133,7 @@ export const authMiddleware = async (req, res, next) => {
} catch {
if (req.cookies.token) clearTokenCookie(res);
if (isDocs || isOAuthAuthorize) return next();
return respondWithAuthPayload(res, req, 401, { error: 'Invalid token' });
return await respondWithAuthPayload(res, req, 401, { error: 'Invalid token' });
}
};