mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-02-14 05:24:24 +01:00
📬 refactor: Normalize Email Handling in User Methods (#10743)
- Updated the `findUser` method to normalize email fields to lowercase and trimmed whitespace for case-insensitive matching. - Enhanced the `normalizeEmailInCriteria` function to handle email normalization in search criteria, including `` conditions. - Added tests to ensure email normalization works correctly across various scenarios, including case differences and whitespace handling.
This commit is contained in:
parent
d7ce19e15a
commit
d5d362e52b
7 changed files with 847 additions and 4 deletions
|
|
@ -44,6 +44,7 @@ export function createTokenMethods(mongoose: typeof import('mongoose')) {
|
|||
|
||||
/**
|
||||
* Deletes all Token documents that match the provided token, user ID, or email.
|
||||
* Email is automatically normalized to lowercase for case-insensitive matching.
|
||||
*/
|
||||
async function deleteTokens(query: TokenQuery): Promise<TokenDeleteResult> {
|
||||
try {
|
||||
|
|
@ -57,7 +58,7 @@ export function createTokenMethods(mongoose: typeof import('mongoose')) {
|
|||
conditions.push({ token: query.token });
|
||||
}
|
||||
if (query.email !== undefined) {
|
||||
conditions.push({ email: query.email });
|
||||
conditions.push({ email: query.email.trim().toLowerCase() });
|
||||
}
|
||||
if (query.identifier !== undefined) {
|
||||
conditions.push({ identifier: query.identifier });
|
||||
|
|
@ -81,6 +82,7 @@ export function createTokenMethods(mongoose: typeof import('mongoose')) {
|
|||
|
||||
/**
|
||||
* Finds a Token document that matches the provided query.
|
||||
* Email is automatically normalized to lowercase for case-insensitive matching.
|
||||
*/
|
||||
async function findToken(query: TokenQuery, options?: QueryOptions): Promise<IToken | null> {
|
||||
try {
|
||||
|
|
@ -94,7 +96,7 @@ export function createTokenMethods(mongoose: typeof import('mongoose')) {
|
|||
conditions.push({ token: query.token });
|
||||
}
|
||||
if (query.email) {
|
||||
conditions.push({ email: query.email });
|
||||
conditions.push({ email: query.email.trim().toLowerCase() });
|
||||
}
|
||||
if (query.identifier) {
|
||||
conditions.push({ identifier: query.identifier });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue