mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-18 01:10:14 +01:00
fix(config/scripts): Enhance User Creation and Ban Handling, Standardize Imports (#1144)
* chore: use relative imports for scripts * fix(create-user): newUser.save() now properly awaited, double-check user creation, use relative imports, catch exception * fix(ban-user): catch exception, handle case where IP is undefined, proper check of user ban on login
This commit is contained in:
parent
a2ee57568a
commit
5f3ecef575
7 changed files with 102 additions and 27 deletions
10
api/cache/banViolation.js
vendored
10
api/cache/banViolation.js
vendored
|
|
@ -54,11 +54,17 @@ const banViolation = async (req, res, errorMessage) => {
|
|||
}
|
||||
|
||||
req.ip = removePorts(req);
|
||||
console.log(`[BAN] Banning user ${user_id} @ ${req.ip} for ${duration / 1000 / 60} minutes`);
|
||||
console.log(
|
||||
`[BAN] Banning user ${user_id} ${req.ip ? `@ ${req.ip} ` : ''}for ${
|
||||
duration / 1000 / 60
|
||||
} minutes`,
|
||||
);
|
||||
|
||||
const expiresAt = Date.now() + duration;
|
||||
await banLogs.set(user_id, { type, violation_count, duration, expiresAt });
|
||||
await banLogs.set(req.ip, { type, user_id, violation_count, duration, expiresAt });
|
||||
if (req.ip) {
|
||||
await banLogs.set(req.ip, { type, user_id, violation_count, duration, expiresAt });
|
||||
}
|
||||
|
||||
errorMessage.ban = true;
|
||||
errorMessage.ban_duration = duration;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue