mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-23 10:46:12 +01:00
fix(models): update user and token operations to use centralized functions
This commit is contained in:
parent
6e278f6932
commit
3831ad8202
10 changed files with 48 additions and 58 deletions
|
|
@ -1,8 +1,6 @@
|
|||
const mongoose = require('mongoose');
|
||||
const { findToken, updateToken, createToken } = require('~/models');
|
||||
const { encryptV2 } = require('~/server/utils/crypto');
|
||||
|
||||
const Token = require('~/db/models').Token;
|
||||
|
||||
/**
|
||||
* Handles the OAuth token by creating or updating the token.
|
||||
* @param {object} fields
|
||||
|
|
@ -31,11 +29,11 @@ async function handleOAuthToken({
|
|||
expiresIn: parseInt(expiresIn, 10) || 3600,
|
||||
};
|
||||
|
||||
const existingToken = await Token.findToken({ userId, identifier });
|
||||
const existingToken = await findToken({ userId, identifier });
|
||||
if (existingToken) {
|
||||
return await Token.updateToken({ identifier }, tokenData);
|
||||
return await updateToken({ identifier }, tokenData);
|
||||
} else {
|
||||
return await Token.createToken(tokenData);
|
||||
return await createToken(tokenData);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
const mongoose = require('mongoose');
|
||||
const { logger } = require('@librechat/data-schemas');
|
||||
const { getRandomValues, hashToken } = require('~/server/utils/crypto');
|
||||
|
||||
const Token = require('~/db/models').Token;
|
||||
const { createToken, findToken } = require('~/models');
|
||||
|
||||
/**
|
||||
* @module inviteUser
|
||||
|
|
@ -24,7 +23,7 @@ const createInvite = async (email) => {
|
|||
|
||||
const fakeUserId = new mongoose.Types.ObjectId();
|
||||
|
||||
await Token.createToken({
|
||||
await createToken({
|
||||
userId: fakeUserId,
|
||||
email,
|
||||
token: hash,
|
||||
|
|
@ -51,7 +50,7 @@ const getInvite = async (encodedToken, email) => {
|
|||
try {
|
||||
const token = decodeURIComponent(encodedToken);
|
||||
const hash = await hashToken(token);
|
||||
const invite = await Token.findToken({ token: hash, email });
|
||||
const invite = await findToken({ token: hash, email });
|
||||
|
||||
if (!invite) {
|
||||
throw new Error('Invite not found or email does not match');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue