u
This commit is contained in:
@@ -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' });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user