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).toHaveLength(1);
|
||||||
expect(user[0]).containSubset({
|
expect(user[0]).containSubset({
|
||||||
id: defaultOwnerId,
|
id: defaultOwnerId,
|
||||||
name: "ABC",
|
name: "abc",
|
||||||
email: "abc@gmail.com",
|
email: "abc@gmail.com",
|
||||||
emailVerified,
|
emailVerified,
|
||||||
});
|
});
|
||||||
@@ -272,7 +272,7 @@ describe("editProfile shoud update user", () => {
|
|||||||
expect(user).toHaveLength(1);
|
expect(user).toHaveLength(1);
|
||||||
expect(user[0]).containSubset({
|
expect(user[0]).containSubset({
|
||||||
id: defaultOwnerId,
|
id: defaultOwnerId,
|
||||||
name: "ABC",
|
name: "abc",
|
||||||
email: "myNewEmail@gmail.com",
|
email: "myNewEmail@gmail.com",
|
||||||
emailVerified: null,
|
emailVerified: null,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -523,12 +523,10 @@ const createUserAsync = async (db: Database, input: Omit<z.infer<typeof validati
|
|||||||
const salt = await createSaltAsync();
|
const salt = await createSaltAsync();
|
||||||
const hashedPassword = await hashPasswordAsync(input.password, salt);
|
const hashedPassword = await hashPasswordAsync(input.password, salt);
|
||||||
|
|
||||||
const username = input.username.toLowerCase();
|
|
||||||
|
|
||||||
const userId = createId();
|
const userId = createId();
|
||||||
await db.insert(users).values({
|
await db.insert(users).values({
|
||||||
id: userId,
|
id: userId,
|
||||||
name: username,
|
name: input.username,
|
||||||
email: input.email,
|
email: input.email,
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
salt,
|
salt,
|
||||||
@@ -543,7 +541,7 @@ const checkUsernameAlreadyTakenAndThrowAsync = async (
|
|||||||
ignoreId?: string,
|
ignoreId?: string,
|
||||||
) => {
|
) => {
|
||||||
const user = await db.query.users.findFirst({
|
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;
|
if (!user) return;
|
||||||
|
|||||||
@@ -7,7 +7,8 @@ import type { TranslationObject } from "@homarr/translation";
|
|||||||
import { zodEnumFromArray } from "./enums";
|
import { zodEnumFromArray } from "./enums";
|
||||||
import { createCustomErrorParams } from "./form/i18n";
|
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);
|
const regexCheck = (regex: RegExp) => (value: string) => regex.test(value);
|
||||||
export const passwordRequirements = [
|
export const passwordRequirements = [
|
||||||
|
|||||||
Reference in New Issue
Block a user