Created
August 8, 2025 21:15
-
-
Save maravedi/82bbc24fd535c67aab021665e3e2b7df to your computer and use it in GitHub Desktop.
update-user.js script for LibreChat
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const path = require('path'); | |
const readline = require('readline'); | |
const mongoose = require(path.resolve(__dirname, '..', 'api', 'node_modules', 'mongoose')); | |
const { User } = require('@librechat/data-schemas').createModels(mongoose); | |
const { SystemRoles } = require('librechat-data-provider'); | |
require('module-alias')({ base: path.resolve(__dirname, '..', 'api') }); | |
const connect = require('./connect'); | |
const rl = readline.createInterface({ | |
input: process.stdin, | |
output: process.stdout, | |
}); | |
const question = (query) => new Promise((resolve) => rl.question(query, resolve)); | |
const updateUser = async () => { | |
try { | |
await connect(); | |
const email = await question('Enter user email: '); | |
const user = await User.findOne({ email }); | |
if (!user) { | |
console.error('User not found!'); | |
process.exit(1); | |
} | |
let validInput = false; | |
let newInput; | |
while (!validInput) { | |
availableRoles = Object.keys(SystemRoles); | |
newInput = await question(`Which role do you want to assign to this user? (${availableRoles.join(', ')}): `); | |
if (!availableRoles.includes(newInput)) { | |
console.log('Invalid role! Please try again.'); | |
continue; | |
} | |
validInput = true; | |
} | |
await User.updateOne( | |
{ email }, | |
{ | |
role: newInput, | |
}, | |
); | |
console.log('User updated successfully!'); | |
process.exit(0); | |
} catch (err) { | |
console.error('Error updating user:', err); | |
process.exit(1); | |
} finally { | |
rl.close(); | |
} | |
}; | |
updateUser(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment