fix(models): update user and token operations to use centralized functions

This commit is contained in:
Danny Avila 2025-05-30 13:59:30 -04:00
parent 6e278f6932
commit 3831ad8202
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
10 changed files with 48 additions and 58 deletions

View file

@ -1,9 +1,7 @@
const mongoose = require('mongoose');
const { logger } = require('@librechat/data-schemas');
const { SystemRoles } = require('librechat-data-provider');
const { Strategy: JwtStrategy, ExtractJwt } = require('passport-jwt');
const User = require('~/db/models').User;
const { getUserById, updateUser } = require('~/models');
// JWT strategy
const jwtLogin = () =>
@ -14,12 +12,12 @@ const jwtLogin = () =>
},
async (payload, done) => {
try {
const user = await User.getUserById(payload?.id, '-password -__v -totpSecret');
const user = await getUserById(payload?.id, '-password -__v -totpSecret');
if (user) {
user.id = user._id.toString();
if (!user.role) {
user.role = SystemRoles.USER;
await User.updateUser(user.id, { role: user.role });
await updateUser(user.id, { role: user.role });
}
done(null, user);
} else {