mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-02 06:10:18 +01:00
🪙 refactor: Auth Token Retrieval with Sorting and Query Options (#9884)
This commit is contained in:
parent
a1471c2f37
commit
c0eb19730a
3 changed files with 201 additions and 8 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import type { QueryOptions } from 'mongoose';
|
||||
import { IToken, TokenCreateData, TokenQuery, TokenUpdateData, TokenDeleteResult } from '~/types';
|
||||
import logger from '~/config/winston';
|
||||
|
||||
|
|
@ -81,7 +82,7 @@ export function createTokenMethods(mongoose: typeof import('mongoose')) {
|
|||
/**
|
||||
* Finds a Token document that matches the provided query.
|
||||
*/
|
||||
async function findToken(query: TokenQuery): Promise<IToken | null> {
|
||||
async function findToken(query: TokenQuery, options?: QueryOptions): Promise<IToken | null> {
|
||||
try {
|
||||
const Token = mongoose.models.Token;
|
||||
const conditions = [];
|
||||
|
|
@ -99,9 +100,7 @@ export function createTokenMethods(mongoose: typeof import('mongoose')) {
|
|||
conditions.push({ identifier: query.identifier });
|
||||
}
|
||||
|
||||
const token = await Token.findOne({
|
||||
$and: conditions,
|
||||
}).lean();
|
||||
const token = await Token.findOne({ $and: conditions }, null, options).lean();
|
||||
|
||||
return token as IToken | null;
|
||||
} catch (error) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue