mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-17 00:40:14 +01:00
* 🧹 chore: Update logger imports to use @librechat/data-schemas across multiple files and remove unused sleep function from queue.js (#9930) * chore: Replace local isEnabled utility with @librechat/api import across multiple files, update test files * chore: Replace local logger import with @librechat/data-schemas logger in countTokens.js and fork.js * chore: Update logs volume path in docker-compose.yml to correct directory * chore: import order of isEnabled in static.js
28 lines
1 KiB
JavaScript
28 lines
1 KiB
JavaScript
const { isEnabled } = require('@librechat/api');
|
|
const { logger } = require('@librechat/data-schemas');
|
|
const { SystemRoles } = require('librechat-data-provider');
|
|
|
|
/**
|
|
* Checks if the user can delete their account
|
|
*
|
|
* @async
|
|
* @function
|
|
* @param {Object} req - Express request object
|
|
* @param {Object} res - Express response object
|
|
* @param {Function} next - Next middleware function
|
|
*
|
|
* @returns {Promise<function|Object>} - Returns a Promise which when resolved calls next middleware if the user can delete their account
|
|
*/
|
|
|
|
const canDeleteAccount = async (req, res, next = () => {}) => {
|
|
const { user } = req;
|
|
const { ALLOW_ACCOUNT_DELETION = true } = process.env;
|
|
if (user?.role === SystemRoles.ADMIN || isEnabled(ALLOW_ACCOUNT_DELETION)) {
|
|
return next();
|
|
} else {
|
|
logger.error(`[User] [Delete Account] [User cannot delete account] [User: ${user?.id}]`);
|
|
return res.status(403).send({ message: 'You do not have permission to delete this account' });
|
|
}
|
|
};
|
|
|
|
module.exports = canDeleteAccount;
|