fix(users): edit profile username not lowercase (#2279)
This commit is contained in:
@@ -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,
|
||||
});
|
||||
|
||||
@@ -523,12 +523,10 @@ const createUserAsync = async (db: Database, input: Omit<z.infer<typeof validati
|
||||
const salt = await createSaltAsync();
|
||||
const hashedPassword = await hashPasswordAsync(input.password, salt);
|
||||
|
||||
const username = input.username.toLowerCase();
|
||||
|
||||
const userId = createId();
|
||||
await db.insert(users).values({
|
||||
id: userId,
|
||||
name: username,
|
||||
name: input.username,
|
||||
email: input.email,
|
||||
password: hashedPassword,
|
||||
salt,
|
||||
@@ -543,7 +541,7 @@ const checkUsernameAlreadyTakenAndThrowAsync = async (
|
||||
ignoreId?: string,
|
||||
) => {
|
||||
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;
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user