From b7fd2470ee0d85821f79a34e839e62fbab6989c6 Mon Sep 17 00:00:00 2001 From: Meier Lukas Date: Sun, 9 Feb 2025 19:09:48 +0100 Subject: [PATCH] fix(users): edit profile username not lowercase (#2279) --- packages/api/src/router/test/user.spec.ts | 4 ++-- packages/api/src/router/user.ts | 6 ++---- packages/validation/src/user.ts | 3 ++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/api/src/router/test/user.spec.ts b/packages/api/src/router/test/user.spec.ts index fc5f5af13..b3af6f7a5 100644 --- a/packages/api/src/router/test/user.spec.ts +++ b/packages/api/src/router/test/user.spec.ts @@ -237,7 +237,7 @@ describe("editProfile shoud update user", () => { expect(user).toHaveLength(1); expect(user[0]).containSubset({ id: defaultOwnerId, - name: "ABC", + name: "abc", email: "abc@gmail.com", emailVerified, }); @@ -272,7 +272,7 @@ describe("editProfile shoud update user", () => { expect(user).toHaveLength(1); expect(user[0]).containSubset({ id: defaultOwnerId, - name: "ABC", + name: "abc", email: "myNewEmail@gmail.com", emailVerified: null, }); diff --git a/packages/api/src/router/user.ts b/packages/api/src/router/user.ts index 5ffc41dee..1ce4e1690 100644 --- a/packages/api/src/router/user.ts +++ b/packages/api/src/router/user.ts @@ -523,12 +523,10 @@ const createUserAsync = async (db: Database, input: Omit { const user = await db.query.users.findFirst({ - where: and(eq(users.name, username.toLowerCase()), eq(users.provider, provider)), + where: and(eq(users.name, username), eq(users.provider, provider)), }); if (!user) return; diff --git a/packages/validation/src/user.ts b/packages/validation/src/user.ts index 99464364e..91eae05eb 100644 --- a/packages/validation/src/user.ts +++ b/packages/validation/src/user.ts @@ -7,7 +7,8 @@ import type { TranslationObject } from "@homarr/translation"; import { zodEnumFromArray } from "./enums"; import { createCustomErrorParams } from "./form/i18n"; -const usernameSchema = z.string().min(3).max(255); +// We always want the lowercase version of the username to compare it in a case-insensitive way +const usernameSchema = z.string().trim().toLowerCase().min(3).max(255); const regexCheck = (regex: RegExp) => (value: string) => regex.test(value); export const passwordRequirements = [