mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-20 02:10:15 +01:00
Move usermethods and models to data-schema
This commit is contained in:
parent
4808c5be48
commit
4049b5572c
93 changed files with 2396 additions and 1267 deletions
|
|
@ -8,10 +8,10 @@ const {
|
|||
requestPasswordReset,
|
||||
setOpenIDAuthTokens,
|
||||
} = require('~/server/services/AuthService');
|
||||
const { findSession, getUserById, deleteAllUserSessions, findUser } = require('~/models');
|
||||
const { getOpenIdConfig } = require('~/strategies');
|
||||
const { logger } = require('~/config');
|
||||
const { isEnabled } = require('~/server/utils');
|
||||
const db = require('~/lib/db/connectDb');
|
||||
|
||||
const registrationController = async (req, res) => {
|
||||
try {
|
||||
|
|
@ -48,7 +48,7 @@ const resetPasswordController = async (req, res) => {
|
|||
if (resetPasswordService instanceof Error) {
|
||||
return res.status(400).json(resetPasswordService);
|
||||
} else {
|
||||
await deleteAllUserSessions({ userId: req.body.userId });
|
||||
await db.models.Session.deleteAllUserSessions({ userId: req.body.userId });
|
||||
return res.status(200).json(resetPasswordService);
|
||||
}
|
||||
} catch (e) {
|
||||
|
|
@ -83,7 +83,7 @@ const refreshController = async (req, res) => {
|
|||
}
|
||||
try {
|
||||
const payload = jwt.verify(refreshToken, process.env.JWT_REFRESH_SECRET);
|
||||
const user = await getUserById(payload.id, '-password -__v -totpSecret');
|
||||
const user = await db.models.User.getUserById(payload.id, '-password -__v -totpSecret');
|
||||
if (!user) {
|
||||
return res.status(401).redirect('/login');
|
||||
}
|
||||
|
|
@ -96,7 +96,10 @@ const refreshController = async (req, res) => {
|
|||
}
|
||||
|
||||
// Find the session with the hashed refresh token
|
||||
const session = await findSession({ userId: userId, refreshToken: refreshToken });
|
||||
const session = await db.models.Session.findSession({
|
||||
userId: userId,
|
||||
refreshToken: refreshToken,
|
||||
});
|
||||
|
||||
if (session && session.expiration > new Date()) {
|
||||
const token = await setAuthTokens(userId, res, session._id);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue