fixed members login and permissions issues

This commit is contained in:
2026-02-23 00:57:34 +00:00
parent ed0debfeac
commit 97da2e2736
42 changed files with 574 additions and 113 deletions
+13 -11
View File
@@ -49,20 +49,22 @@ export function rateLimiter(options: RateLimiterOptions): MiddlewareHandler {
const now = Date.now();
const entry = store.get(key);
if (entry && entry.resetAt > now) {
if (entry.count >= max) {
const retryAfter = Math.ceil((entry.resetAt - now) / 1000);
throw errors.TOO_MANY_REQUESTS(message, retryAfter);
}
entry.count++;
} else {
store.set(key, {
count: 1,
resetAt: now + windowMs,
});
if (entry && entry.resetAt > now && entry.count >= max) {
const retryAfter = Math.ceil((entry.resetAt - now) / 1000);
throw errors.TOO_MANY_REQUESTS(message, retryAfter);
}
await next();
// Only count failed attempts (4xx status codes)
const status = ctx.res.status;
if (status >= 400 && status < 500) {
if (entry && entry.resetAt > now) {
entry.count++;
} else {
store.set(key, { count: 1, resetAt: now + windowMs });
}
}
};
}
+1 -1
View File
@@ -7,7 +7,7 @@ import { officerdb, eq, Users, TokenBlacklist } from 'officerdb';
// Role permissions: which HTTP methods each role can use
// Roles not listed here are denied by default (fail-safe)
const ROLE_PERMISSIONS: Record<string, string[]> = {
Member: ['GET'],
Member: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
Admin: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
Owner: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
'Super Admin': ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],