From 27325326da381f9f9a746f207b7a19f9d1f5f5b1 Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Thu, 21 May 2026 16:29:27 +0200 Subject: [PATCH 1/5] fix(auth): resolve credentials login SQLITE_CONSTRAINT_NOTNULL and relax password rules Session creation failed with NOT NULL constraint on expires column due to invalid date propagation from duration parsing. Override adapter.createSession with validated insert, harden signIn callback, fix createDurationSchema for numeric-only values, and guard events.ts group insert. Also relaxes password complexity to suggestions-only (min 8 chars enforced), extracts shared UserCreatePasswordFields component, and fixes login form passing extra fields to signIn. --- Dockerfile | 2 - .../app/[locale]/auth/login/_login-form.tsx | 9 ++- .../init/_steps/user/init-user-form.tsx | 12 ++-- .../_components/create-user-stepper.tsx | 18 ++---- e2e/onboarding.spec.ts | 31 ++++++++++ packages/api/src/router/test/user.spec.ts | 58 ++++++++++++++++--- packages/auth/adapter.ts | 13 +++++ packages/auth/configuration.ts | 6 ++ packages/auth/events.ts | 2 +- packages/auth/test/adapter.spec.ts | 31 ++++++++++ packages/auth/test/security.spec.ts | 8 +++ .../core/src/infrastructure/env/schemas.ts | 31 +++++----- packages/forms-collection/src/index.tsx | 2 + .../user-create-password-fields.tsx | 37 ++++++++++++ packages/redis/src/lib/channel.ts | 16 ++++- packages/redis/src/lib/connection.ts | 9 +-- packages/translation/src/lang/en.json | 11 ++-- .../password-input/password-input.tsx | 7 ++- .../password-input/password-requirement.tsx | 23 +++++--- .../password-requirements-popover.tsx | 18 ++++-- packages/validation/src/user.ts | 16 +---- 21 files changed, 274 insertions(+), 86 deletions(-) create mode 100644 packages/forms-collection/src/user-create/user-create-password-fields.tsx diff --git a/Dockerfile b/Dockerfile index 51b562f7d..1c1388ec5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,8 +15,6 @@ RUN corepack enable pnpm && pnpm install --recursive --frozen-lockfile # Copy static data as it is not part of the build COPY static-data ./static-data ARG SKIP_ENV_VALIDATION='true' -ARG CI='true' -ARG DISABLE_REDIS_LOGS='true' RUN corepack enable pnpm && pnpm build diff --git a/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx b/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx index 71d249cf5..4bf393d5f 100644 --- a/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx +++ b/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx @@ -115,7 +115,14 @@ export const LoginForm = ({ providers, oidcClientName, isOidcAutoLoginEnabled, c {credentialInputsVisible && ( <> -
void signInAsync(credentials.provider, credentials))}> + + void signInAsync(credentials.provider, { + name: credentials.name, + password: credentials.password, + }), + )} + > { @@ -59,12 +59,10 @@ export const InitUserForm = () => { > - - diff --git a/apps/nextjs/src/app/[locale]/manage/users/create/_components/create-user-stepper.tsx b/apps/nextjs/src/app/[locale]/manage/users/create/_components/create-user-stepper.tsx index fbaae76c7..71eb91bbd 100644 --- a/apps/nextjs/src/app/[locale]/manage/users/create/_components/create-user-stepper.tsx +++ b/apps/nextjs/src/app/[locale]/manage/users/create/_components/create-user-stepper.tsx @@ -6,7 +6,6 @@ import { Button, Card, Group, - PasswordInput, Stack, Stepper, Table, @@ -27,7 +26,8 @@ import { useZodForm } from "@homarr/form"; import { useModalAction } from "@homarr/modals"; import { showErrorNotification } from "@homarr/notifications"; import { useI18n, useScopedI18n } from "@homarr/translation/client"; -import { CustomPasswordInput, UserAvatar } from "@homarr/ui"; +import { UserCreatePasswordFields } from "@homarr/forms-collection"; +import { UserAvatar } from "@homarr/ui"; import { createCustomErrorParams } from "@homarr/validation/form/i18n"; import { userPasswordSchema } from "@homarr/validation/user"; @@ -167,18 +167,10 @@ export const UserCreateStepperComponent = ({ initialGroups }: UserCreateStepperC - - diff --git a/e2e/onboarding.spec.ts b/e2e/onboarding.spec.ts index 7e709f425..887382ea5 100644 --- a/e2e/onboarding.spec.ts +++ b/e2e/onboarding.spec.ts @@ -42,6 +42,37 @@ describe("Onboarding", () => { await homarrContainer.stop(); }, 60_000); + test("Credentials onboarding with special character password should be successful", async () => { + const { db, localMountPath } = await createSqliteDbFileAsync(); + const homarrContainer = await createHomarrContainer({ + mounts: { + "/appdata": localMountPath, + }, + }).start(); + + const browser = await chromium.launch(); + const context = await browser.newContext(); + const page = await context.newPage(); + const actions = new OnboardingActions(page, db); + const assertions = new OnboardingAssertions(page, db); + + await page.goto(`http://${homarrContainer.getHost()}:${homarrContainer.getMappedPort(7575)}`); + await actions.startOnboardingAsync("scratch"); + await actions.processUserStepAsync({ + username: "admin", + password: "LoveHomarr<3", + confirmPassword: "LoveHomarr<3", + }); + await actions.processSettingsStepAsync(); + + await assertions.assertFinishStepVisibleAsync(); + await assertions.assertUserAndAdminGroupInsertedAsync("admin"); + await assertions.assertDbOnboardingStepAsync("finish"); + + await browser.close(); + await homarrContainer.stop(); + }, 60_000); + test("External provider onboarding setup should be successful", async () => { // Arrange const { db, localMountPath } = await createSqliteDbFileAsync(); diff --git a/packages/api/src/router/test/user.spec.ts b/packages/api/src/router/test/user.spec.ts index b3b262846..16cabfd52 100644 --- a/packages/api/src/router/test/user.spec.ts +++ b/packages/api/src/router/test/user.spec.ts @@ -81,13 +81,7 @@ describe("initUser should initialize the first user", () => { await expect(actAsync()).rejects.toThrow("passwordsDoNotMatch"); }); - it.each([ - ["aB2%"], // too short - ["abc123DEF"], // does not contain special characters - ["abcDEFghi+"], // does not contain numbers - ["ABC123+/-"], // does not contain lowercase - ["abc123+/-"], // does not contain uppercase - ])("should throw error that password requirements do not match for '%s' as password", async (password) => { + it.each([["aB2%"], ["short"]])("should reject passwords shorter than 8 characters for '%s'", async (password) => { const db = createDb(); await createOnboardingStepAsync(db, "user"); const caller = userRouter.createCaller({ @@ -103,7 +97,55 @@ describe("initUser should initialize the first user", () => { confirmPassword: password, }); - await expect(actAsync()).rejects.toThrow("passwordRequirements"); + await expect(actAsync()).rejects.toThrow(); + }); + + it("should accept passwords without complexity requirements", async () => { + const db = createDb(); + await createOnboardingStepAsync(db, "user"); + const caller = userRouter.createCaller({ + db, + deviceType: undefined, + session: null, + }); + + await caller.initUser({ + username: "test", + password: "abc123DEF", + confirmPassword: "abc123DEF", + }); + + const user = await db.query.users.findFirst({ + columns: { + id: true, + }, + }); + + expect(user).toBeDefined(); + }); + + it("should accept passwords with special characters like LoveHomarr<3", async () => { + const db = createDb(); + await createOnboardingStepAsync(db, "user"); + const caller = userRouter.createCaller({ + db, + deviceType: undefined, + session: null, + }); + + await caller.initUser({ + username: "test", + password: "LoveHomarr<3", + confirmPassword: "LoveHomarr<3", + }); + + const user = await db.query.users.findFirst({ + columns: { + id: true, + }, + }); + + expect(user).toBeDefined(); }); }); diff --git a/packages/auth/adapter.ts b/packages/auth/adapter.ts index 30984a403..c33982ff1 100644 --- a/packages/auth/adapter.ts +++ b/packages/auth/adapter.ts @@ -11,6 +11,19 @@ export const createAdapter = (db: Database, provider: SupportedAuthProvider | "u return { ...drizzleAdapter, + createSession: (data) => { + const result = db + .insert(sessions) + .values({ + sessionToken: data.sessionToken, + userId: data.userId, + expires: data.expires, + }) + .returning() + .get(); + + return result; + }, // We override the default implementation as we want to have a provider // flag in the user instead of the account to not intermingle users from different providers // eslint-disable-next-line no-restricted-syntax diff --git a/packages/auth/configuration.ts b/packages/auth/configuration.ts index b0181e326..21a44a293 100644 --- a/packages/auth/configuration.ts +++ b/packages/auth/configuration.ts @@ -71,6 +71,12 @@ export const createConfiguration = ( const expires = expireDateAfter(env.AUTH_SESSION_EXPIRY_TIME); const sessionToken = generateSessionToken(); + + if (Number.isNaN(expires.getTime())) { + logger.error("Invalid session expiry date", { expirySeconds: env.AUTH_SESSION_EXPIRY_TIME }); + return false; + } + await adapter.createSession({ sessionToken, expires, diff --git a/packages/auth/events.ts b/packages/auth/events.ts index 2593c418b..acd53cc8b 100644 --- a/packages/auth/events.ts +++ b/packages/auth/events.ts @@ -99,7 +99,7 @@ const addUserToEveryoneGroupIfNotMemberAsync = async (db: Database, userId: stri }, }); - if (dbEveryoneGroup?.members.length === 0) { + if (dbEveryoneGroup?.id && dbEveryoneGroup.members.length === 0) { await db.insert(groupMembers).values({ userId, groupId: dbEveryoneGroup.id, diff --git a/packages/auth/test/adapter.spec.ts b/packages/auth/test/adapter.spec.ts index d20ae3d1a..b2b0a4ca5 100644 --- a/packages/auth/test/adapter.spec.ts +++ b/packages/auth/test/adapter.spec.ts @@ -1,11 +1,42 @@ +/** + * @vitest-environment node + */ import { describe, expect, test } from "vitest"; +import { createId } from "@homarr/common"; import { users } from "@homarr/db/schema"; import { createDb } from "@homarr/db/test"; import { createAdapter } from "../adapter"; +import { expireDateAfter } from "../session"; describe("createAdapter should create drizzle adapter", () => { + test("createSession should insert a session row", async () => { + const db = createDb(); + const userId = createId(); + await db.insert(users).values({ id: userId, name: "demodemo", password: "hash" }); + + const adapter = createAdapter(db, "credentials"); + const sessionToken = "test-session-token"; + + const session = await adapter.createSession?.({ + sessionToken, + userId, + expires: expireDateAfter(86400), + }); + + expect(session).toMatchObject({ + sessionToken, + userId, + }); + + const storedSession = await db.query.sessions.findFirst({ + where: (table, { eq }) => eq(table.sessionToken, sessionToken), + }); + + expect(storedSession).toBeDefined(); + }); + test.each([["credentials" as const], ["ldap" as const], ["oidc" as const]])( "createAdapter getUserByEmail should return user for provider %s when this provider provided", async (provider) => { diff --git a/packages/auth/test/security.spec.ts b/packages/auth/test/security.spec.ts index fee34ec7f..7b3ffd82e 100644 --- a/packages/auth/test/security.spec.ts +++ b/packages/auth/test/security.spec.ts @@ -53,4 +53,12 @@ describe("comparePasswordsAsync should compare passwords correctly", () => { // Assert expect(result).toBe(false); }); + it("should return true for passwords with special characters like LoveHomarr<3", async () => { + const password = "LoveHomarr<3"; + const hash = await hashPasswordAsync(password); + + const result = await comparePasswordsAsync(password, hash); + + expect(result).toBe(true); + }); }); diff --git a/packages/core/src/infrastructure/env/schemas.ts b/packages/core/src/infrastructure/env/schemas.ts index 595dd37ca..4d415b4f1 100644 --- a/packages/core/src/infrastructure/env/schemas.ts +++ b/packages/core/src/infrastructure/env/schemas.ts @@ -12,25 +12,26 @@ export const createBooleanSchema = (defaultValue: boolean) => }) .default(defaultValue); -export const createDurationSchema = (defaultValue: `${number}${"s" | "m" | "h" | "d"}`) => - z +export const createDurationSchema = (defaultValue: `${number}${"s" | "m" | "h" | "d"}`) => { + const defaultMultipliers = { + s: 1, + m: 60, + h: 60 * 60, + d: 60 * 60 * 24, + } as const; + + return z .string() .regex(/^\d+[smhd]?$/) .default(defaultValue) .transform((duration) => { - const lastChar = duration[duration.length - 1] as "s" | "m" | "h" | "d"; - if (!isNaN(Number(lastChar))) { - return Number(defaultValue); + const unit = duration.at(-1) as keyof typeof defaultMultipliers | undefined; + const multiplier = unit ? defaultMultipliers[unit] : undefined; + + if (multiplier) { + return Number(duration.slice(0, -1)) * multiplier; } - const multipliers = { - s: 1, - m: 60, - h: 60 * 60, - d: 60 * 60 * 24, - }; - const numberDuration = Number(duration.slice(0, -1)); - const multiplier = multipliers[lastChar]; - - return numberDuration * multiplier; + return Number(duration); }); +}; diff --git a/packages/forms-collection/src/index.tsx b/packages/forms-collection/src/index.tsx index 218655cb5..7621bed43 100644 --- a/packages/forms-collection/src/index.tsx +++ b/packages/forms-collection/src/index.tsx @@ -5,3 +5,5 @@ export * from "./icon-picker/icon-picker"; export * from "./new-app/icon-matcher"; export * from "./upload-media/upload-media"; + +export * from "./user-create/user-create-password-fields"; diff --git a/packages/forms-collection/src/user-create/user-create-password-fields.tsx b/packages/forms-collection/src/user-create/user-create-password-fields.tsx new file mode 100644 index 000000000..a2753c4bc --- /dev/null +++ b/packages/forms-collection/src/user-create/user-create-password-fields.tsx @@ -0,0 +1,37 @@ +"use client"; + +import { PasswordInput, Stack } from "@mantine/core"; +import type { PasswordInputProps } from "@mantine/core"; + +import { useScopedI18n } from "@homarr/translation/client"; +import { CustomPasswordInput } from "@homarr/ui"; + +interface UserCreatePasswordFieldsProps { + passwordInputProps: PasswordInputProps; + confirmPasswordInputProps: PasswordInputProps; + variant?: PasswordInputProps["variant"]; +} + +export const UserCreatePasswordFields = ({ + passwordInputProps, + confirmPasswordInputProps, + variant, +}: UserCreatePasswordFieldsProps) => { + const t = useScopedI18n("user.field"); + + return ( + + + + + ); +}; diff --git a/packages/redis/src/lib/channel.ts b/packages/redis/src/lib/channel.ts index 193f551e3..e1031033d 100644 --- a/packages/redis/src/lib/channel.ts +++ b/packages/redis/src/lib/channel.ts @@ -12,6 +12,8 @@ const logger = createLogger({ module: "redisChannel" }); const publisher = createRedisConnection(); const lastDataClient = createRedisConnection(); +const noopSubscription = () => ({ unsubscribe: () => undefined }); + /** * Creates a new pub/sub channel. * @param name name of the channel @@ -26,13 +28,16 @@ export const createSubPubChannel = (name: string, { persist }: { persist: * @param callback callback function to be called when new data is published */ subscribe: (callback: (data: TData) => void) => { - if (persist) { + if (persist && lastDataClient) { void lastDataClient.get(lastChannelName).then((data) => { if (data) { callback(superjson.parse(data)); } }); } + if (!publisher) { + return noopSubscription(); + } return ChannelSubscriptionTracker.subscribe(channelName, (message) => { callback(superjson.parse(message)); }); @@ -42,12 +47,18 @@ export const createSubPubChannel = (name: string, { persist }: { persist: * @param data data to be published */ publishAsync: async (data: TData) => { + if (!publisher || !lastDataClient) { + return; + } if (persist) { await lastDataClient.set(lastChannelName, superjson.stringify(data)); } await publisher.publish(channelName, superjson.stringify(data)); }, getLastDataAsync: async () => { + if (!lastDataClient) { + return null; + } const data = await lastDataClient.get(lastChannelName); return data ? superjson.parse(data) : null; }, @@ -187,6 +198,9 @@ export const createCacheChannel = (name: string, cacheDurationMs: number * Invalidate the cache channels data. */ invalidateAsync: async () => { + if (!getSetClient) { + return; + } await getSetClient.del(cacheChannelName); }, /** diff --git a/packages/redis/src/lib/connection.ts b/packages/redis/src/lib/connection.ts index ba945de33..8b8bda3f1 100644 --- a/packages/redis/src/lib/connection.ts +++ b/packages/redis/src/lib/connection.ts @@ -5,10 +5,11 @@ import { createRedisClient } from "@homarr/core/infrastructure/redis"; * Creates a new Redis connection * @returns redis client */ -export const createRedisConnection = () => { - if (Boolean(process.env.CI) || Boolean(process.env.DISABLE_REDIS_LOGS)) { - // Return null if we are in CI as we don't want to connect to Redis - return null as unknown as RedisClient; +export const createRedisConnection = (): RedisClient | null => { + const disableRedisLogs = process.env["DISABLE_REDIS_LOGS"] === "true"; + + if (disableRedisLogs) { + return null; } return createRedisClient(); diff --git a/packages/translation/src/lang/en.json b/packages/translation/src/lang/en.json index 29e86458e..5e742c7c4 100644 --- a/packages/translation/src/lang/en.json +++ b/packages/translation/src/lang/en.json @@ -132,12 +132,13 @@ }, "password": { "label": "Password", + "suggestionsTitle": "Password suggestions", "requirement": { - "length": "Includes at least 8 characters", - "lowercase": "Includes lowercase letter", - "uppercase": "Includes uppercase letter", - "number": "Includes number", - "special": "Includes special symbol" + "length": "At least 8 characters", + "lowercase": "Suggested: includes lowercase letter", + "uppercase": "Suggested: includes uppercase letter", + "number": "Suggested: includes number", + "special": "Suggested: includes special symbol" } }, "passwordConfirm": { diff --git a/packages/ui/src/components/password-input/password-input.tsx b/packages/ui/src/components/password-input/password-input.tsx index 6164ede02..13141d39a 100644 --- a/packages/ui/src/components/password-input/password-input.tsx +++ b/packages/ui/src/components/password-input/password-input.tsx @@ -20,15 +20,16 @@ export const CustomPasswordInput = ({ withPasswordRequirements, ...props }: Cust }; const WithPasswordRequirements = (props: PasswordInputProps) => { - const [value, setValue] = useState(""); + const [internalValue, setInternalValue] = useState(""); + const password = props.value ?? internalValue; const onChange = (event: ChangeEvent) => { - setValue(event.currentTarget.value); + setInternalValue(event.currentTarget.value); props.onChange?.(event); }; return ( - + ); diff --git a/packages/ui/src/components/password-input/password-requirement.tsx b/packages/ui/src/components/password-input/password-requirement.tsx index 1e1eca197..5031bf5c8 100644 --- a/packages/ui/src/components/password-input/password-requirement.tsx +++ b/packages/ui/src/components/password-input/password-requirement.tsx @@ -1,14 +1,23 @@ import { rem, Text } from "@mantine/core"; -import { IconCheck, IconX } from "@tabler/icons-react"; +import { IconCheck, IconPoint } from "@tabler/icons-react"; + +const requirementDisplay = { + met: { color: "teal", Icon: IconCheck }, + unmet: { color: "dimmed", Icon: IconPoint }, +} as const; + +const displayKey = { + true: "met", + false: "unmet", +} as const; export function PasswordRequirement({ meets, label }: { meets: boolean; label: string }) { + const display = requirementDisplay[displayKey[String(meets) as "true" | "false"]]; + const Icon = display.Icon; + return ( - - {meets ? ( - - ) : ( - - )} + + {label} diff --git a/packages/ui/src/components/password-input/password-requirements-popover.tsx b/packages/ui/src/components/password-input/password-requirements-popover.tsx index 5d10611f9..e61da060e 100644 --- a/packages/ui/src/components/password-input/password-requirements-popover.tsx +++ b/packages/ui/src/components/password-input/password-requirements-popover.tsx @@ -1,16 +1,25 @@ import type { PropsWithChildren } from "react"; import { useState } from "react"; -import { Popover, Progress } from "@mantine/core"; +import { Popover, Progress, Text } from "@mantine/core"; import { useScopedI18n } from "@homarr/translation/client"; import { passwordRequirements } from "@homarr/validation/user"; import { PasswordRequirement } from "./password-requirement"; +const strengthColorMap = [ + { min: 100, color: "teal" }, + { min: 51, color: "yellow" }, + { min: 0, color: "dimmed" }, +] as const; + export const PasswordRequirementsPopover = ({ password, children }: PropsWithChildren<{ password: string }>) => { + const tPassword = useScopedI18n("user.field.password"); const requirements = useRequirements(); const strength = useStrength(password); const [popoverOpened, setPopoverOpened] = useState(false); + const strengthColor = + strengthColorMap.find(({ min }) => strength >= min)?.color ?? strengthColorMap[strengthColorMap.length - 1].color; const checks = ( <> {requirements.map((requirement) => ( @@ -19,8 +28,6 @@ export const PasswordRequirementsPopover = ({ password, children }: PropsWithChi ); - const color = strength === 100 ? "teal" : strength > 50 ? "yellow" : "red"; - return ( @@ -29,7 +36,10 @@ export const PasswordRequirementsPopover = ({ password, children }: PropsWithChi - + + + {tPassword("suggestionsTitle")} + {checks} diff --git a/packages/validation/src/user.ts b/packages/validation/src/user.ts index 626ba2e8b..b94e65015 100644 --- a/packages/validation/src/user.ts +++ b/packages/validation/src/user.ts @@ -22,21 +22,7 @@ export const passwordRequirements = [ value: keyof TranslationObject["user"]["field"]["password"]["requirement"]; }[]; -export const userPasswordSchema = z - .string() - .min(8) - .max(255) - .refine( - (value) => { - return passwordRequirements.every((requirement) => requirement.check(value)); - }, - { - params: createCustomErrorParams({ - key: "passwordRequirements", - params: {}, - }), - }, - ); +export const userPasswordSchema = z.string().min(8).max(255); const addConfirmPasswordRefinement = < TSchema extends z.ZodObject<{ password: z.core.$ZodString; confirmPassword: z.core.$ZodString }, z.core.$strip>, From 63d50ed5fb96d8b1e5f49b300dc68d4f94663185 Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Thu, 21 May 2026 16:50:28 +0200 Subject: [PATCH 2/5] fix(ci): resolve format, lint and typecheck failures --- .../app/[locale]/auth/login/_login-form.tsx | 11 +- .../_components/create-user-stepper.tsx | 16 +-- .../user-create-password-fields.tsx | 6 +- .../src/lib/channel-subscription-tracker.ts | 6 +- packages/redis/src/lib/channel.ts | 102 +++++++++--------- packages/redis/src/lib/connection.ts | 2 +- .../password-requirements-popover.tsx | 3 +- 7 files changed, 67 insertions(+), 79 deletions(-) diff --git a/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx b/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx index 4bf393d5f..94b49fa20 100644 --- a/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx +++ b/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx @@ -116,11 +116,12 @@ export const LoginForm = ({ providers, oidcClientName, isOidcAutoLoginEnabled, c {credentialInputsVisible && ( <> - void signInAsync(credentials.provider, { - name: credentials.name, - password: credentials.password, - }), + onSubmit={form.onSubmit( + (credentials) => + void signInAsync(credentials.provider, { + name: credentials.name, + password: credentials.password, + }), )} > diff --git a/apps/nextjs/src/app/[locale]/manage/users/create/_components/create-user-stepper.tsx b/apps/nextjs/src/app/[locale]/manage/users/create/_components/create-user-stepper.tsx index 71eb91bbd..24d379ed6 100644 --- a/apps/nextjs/src/app/[locale]/manage/users/create/_components/create-user-stepper.tsx +++ b/apps/nextjs/src/app/[locale]/manage/users/create/_components/create-user-stepper.tsx @@ -1,19 +1,7 @@ "use client"; import { startTransition, useCallback, useState } from "react"; -import { - Badge, - Button, - Card, - Group, - Stack, - Stepper, - Table, - Text, - TextInput, - Title, - Tooltip, -} from "@mantine/core"; +import { Badge, Button, Card, Group, Stack, Stepper, Table, Text, TextInput, Title, Tooltip } from "@mantine/core"; import { useListState } from "@mantine/hooks"; import { IconPlus, IconUserCheck } from "@tabler/icons-react"; import { z } from "zod/v4"; @@ -23,10 +11,10 @@ import type { GroupPermissionKey } from "@homarr/definitions"; import { everyoneGroup, groupPermissions } from "@homarr/definitions"; import type { IsValid } from "@homarr/form"; import { useZodForm } from "@homarr/form"; +import { UserCreatePasswordFields } from "@homarr/forms-collection"; import { useModalAction } from "@homarr/modals"; import { showErrorNotification } from "@homarr/notifications"; import { useI18n, useScopedI18n } from "@homarr/translation/client"; -import { UserCreatePasswordFields } from "@homarr/forms-collection"; import { UserAvatar } from "@homarr/ui"; import { createCustomErrorParams } from "@homarr/validation/form/i18n"; import { userPasswordSchema } from "@homarr/validation/user"; diff --git a/packages/forms-collection/src/user-create/user-create-password-fields.tsx b/packages/forms-collection/src/user-create/user-create-password-fields.tsx index a2753c4bc..ad7329307 100644 --- a/packages/forms-collection/src/user-create/user-create-password-fields.tsx +++ b/packages/forms-collection/src/user-create/user-create-password-fields.tsx @@ -27,11 +27,7 @@ export const UserCreatePasswordFields = ({ variant={variant} {...passwordInputProps} /> - + ); }; diff --git a/packages/redis/src/lib/channel-subscription-tracker.ts b/packages/redis/src/lib/channel-subscription-tracker.ts index 02adc6897..3c76fd5eb 100644 --- a/packages/redis/src/lib/channel-subscription-tracker.ts +++ b/packages/redis/src/lib/channel-subscription-tracker.ts @@ -42,7 +42,7 @@ export class ChannelSubscriptionTracker { // If there are no subscriptions to the channel, subscribe to it if (channelSubscriptions.size === 0) { logger.debug("Subscribing to redis channel", { channel: channelName }); - void this.redis.subscribe(channelName); + void this.redis?.subscribe(channelName); } logger.debug("Adding redis channel callback", { channel: channelName, id }); @@ -65,7 +65,7 @@ export class ChannelSubscriptionTracker { } logger.debug("Unsubscribing from redis channel", { channel: channelName }); - void this.redis.unsubscribe(channelName); + void this.redis?.unsubscribe(channelName); this.subscriptions.delete(channelName); }; } @@ -75,7 +75,7 @@ export class ChannelSubscriptionTracker { */ private static activateListener() { logger.debug("Activating listener"); - this.redis.on("message", (channel, message) => { + this.redis?.on("message", (channel, message) => { const channelSubscriptions = this.subscriptions.get(channel); if (!channelSubscriptions) { logger.warn("Received message on unknown channel", { channel }); diff --git a/packages/redis/src/lib/channel.ts b/packages/redis/src/lib/channel.ts index e1031033d..d7c8fd4f6 100644 --- a/packages/redis/src/lib/channel.ts +++ b/packages/redis/src/lib/channel.ts @@ -12,7 +12,7 @@ const logger = createLogger({ module: "redisChannel" }); const publisher = createRedisConnection(); const lastDataClient = createRedisConnection(); -const noopSubscription = () => ({ unsubscribe: () => undefined }); +const noopSubscription = (): (() => void) => () => undefined; /** * Creates a new pub/sub channel. @@ -80,28 +80,28 @@ export const createListChannel = (name: string) => { * @returns an array of all items */ getAllAsync: async () => { - const items = await getSetClient.lrange(listChannelName, 0, -1); - return items.map((item) => superjson.parse(item)); + const items = await getSetClient?.lrange(listChannelName, 0, -1); + return items?.map((item) => superjson.parse(item)) ?? []; }, /** * Remove an item from the channels list by item * @param item item to remove */ removeAsync: async (item: TItem) => { - await getSetClient.lrem(listChannelName, 0, superjson.stringify(item)); + await getSetClient?.lrem(listChannelName, 0, superjson.stringify(item)); }, /** * Clear all items from the channels list */ clearAsync: async () => { - await getSetClient.del(listChannelName); + await getSetClient?.del(listChannelName); }, /** * Add an item to the channels list * @param item item to add */ addAsync: async (item: TItem) => { - await getSetClient.lpush(listChannelName, superjson.stringify(item)); + await getSetClient?.lpush(listChannelName, superjson.stringify(item)); }, }; }; @@ -117,7 +117,7 @@ export const createGetSetChannel = (name: string) => { * @returns data or null if not found */ getAsync: async () => { - const data = await getSetClient.get(name); + const data = await getSetClient?.get(name); return data ? superjson.parse(data) : null; }, /** @@ -125,13 +125,13 @@ export const createGetSetChannel = (name: string) => { * @param data data to be stored in the channel */ setAsync: async (data: TData) => { - await getSetClient.set(name, superjson.stringify(data)); + await getSetClient?.set(name, superjson.stringify(data)); }, /** * Remove data from the channel */ removeAsync: async () => { - await getSetClient.del(name); + await getSetClient?.del(name); }, }; }; @@ -151,7 +151,7 @@ export const createCacheChannel = (name: string, cacheDurationMs: number * @returns data or null if not found or expired */ getAsync: async () => { - const data = await getSetClient.get(cacheChannelName); + const data = await getSetClient?.get(cacheChannelName); if (!data) return null; const parsedData = superjson.parse<{ data: TData; timestamp: Date }>(data); @@ -167,13 +167,13 @@ export const createCacheChannel = (name: string, cacheDurationMs: number * @returns data or new data if not present or expired */ consumeAsync: async (callback: () => Promise) => { - const data = await getSetClient.get(cacheChannelName); + const data = await getSetClient?.get(cacheChannelName); const getNewDataAsync = async () => { logger.debug(`Cache miss for channel '${cacheChannelName}'`); const newData = await callback(); const result = { data: newData, timestamp: new Date() }; - await getSetClient.set(cacheChannelName, superjson.stringify(result)); + await getSetClient?.set(cacheChannelName, superjson.stringify(result)); logger.debug(`Cache updated for channel '${cacheChannelName}'`); return result; }; @@ -208,7 +208,7 @@ export const createCacheChannel = (name: string, cacheDurationMs: number * @param data data to be stored in the cache channel */ setAsync: async (data: TData) => { - await getSetClient.set(cacheChannelName, superjson.stringify({ data, timestamp: new Date() })); + await getSetClient?.set(cacheChannelName, superjson.stringify({ data, timestamp: new Date() })); }, }; }; @@ -250,12 +250,12 @@ export const createChannelEventHistory = (channelName: string, maxElement }); }, pushAsync: async (data: TData, options = { publish: false }) => { - if (options.publish) await publisher.publish(channelName, superjson.stringify(data)); - await getSetClient.lpush(channelName, superjson.stringify({ data, timestamp: new Date() })); - await getSetClient.ltrim(channelName, 0, maxElements); + if (options.publish) await publisher?.publish(channelName, superjson.stringify(data)); + await getSetClient?.lpush(channelName, superjson.stringify({ data, timestamp: new Date() })); + await getSetClient?.ltrim(channelName, 0, maxElements); }, clearAsync: async () => { - await getSetClient.del(channelName); + await getSetClient?.del(channelName); }, /** * Returns a slice of the available data in the channel. @@ -264,17 +264,19 @@ export const createChannelEventHistory = (channelName: string, maxElement * @param endIndex End index of the slice, negative values are counted from the end, defaults at end of range. */ getSliceAsync: async (startIndex = 0, endIndex = -1) => { - const range = await getSetClient.lrange(channelName, startIndex, endIndex); - return range.map((item) => superjson.parse<{ data: TData; timestamp: Date }>(item)); + const range = await getSetClient?.lrange(channelName, startIndex, endIndex); + return range?.map((item) => superjson.parse<{ data: TData; timestamp: Date }>(item)) ?? []; }, getSliceUntilTimeAsync: async (time: Date) => { - const itemsInCollection = await getSetClient.lrange(channelName, 0, -1); - return itemsInCollection - .map((item) => superjson.parse<{ data: TData; timestamp: Date }>(item)) - .filter((item) => item.timestamp < time); + const itemsInCollection = await getSetClient?.lrange(channelName, 0, -1); + return ( + itemsInCollection + ?.map((item) => superjson.parse<{ data: TData; timestamp: Date }>(item)) + .filter((item) => item.timestamp < time) ?? [] + ); }, getLengthAsync: async () => { - return await getSetClient.llen(channelName); + return (await getSetClient?.llen(channelName)) ?? 0; }, name: channelName, }; @@ -285,11 +287,11 @@ export const createChannelEventHistory = (channelName: string, maxElement */ export const createChannelEventHistoryOld = (channelName: string, maxElements = 15) => { const popElementsOverMaxAsync = async () => { - const length = await getSetClient.llen(channelName); - if (length <= maxElements) { + const length = await getSetClient?.llen(channelName); + if (!length || length <= maxElements) { return; } - await getSetClient.ltrim(channelName, 0, maxElements - 1); + await getSetClient?.ltrim(channelName, 0, maxElements - 1); }; return { @@ -299,37 +301,39 @@ export const createChannelEventHistoryOld = (channelName: string, maxElem }); }, publishAndPushAsync: async (data: TData) => { - await publisher.publish(channelName, superjson.stringify(data)); - await getSetClient.lpush(channelName, superjson.stringify({ data, timestamp: new Date() })); + await publisher?.publish(channelName, superjson.stringify(data)); + await getSetClient?.lpush(channelName, superjson.stringify({ data, timestamp: new Date() })); await popElementsOverMaxAsync(); }, pushAsync: async (data: TData) => { - await getSetClient.lpush(channelName, superjson.stringify({ data, timestamp: new Date() })); + await getSetClient?.lpush(channelName, superjson.stringify({ data, timestamp: new Date() })); await popElementsOverMaxAsync(); }, clearAsync: async () => { - await getSetClient.del(channelName); + await getSetClient?.del(channelName); }, getLastAsync: async () => { - const length = await getSetClient.llen(channelName); - const data = await getSetClient.lrange(channelName, length - 1, length); - if (data.length !== 1) return null; + const length = await getSetClient?.llen(channelName); + const data = await getSetClient?.lrange(channelName, (length ?? 0) - 1, length ?? 0); + if (data?.length !== 1) return null; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return superjson.parse<{ data: TData; timestamp: Date }>(data[0]!); }, getSliceAsync: async (startIndex: number, endIndex: number) => { - const range = await getSetClient.lrange(channelName, startIndex, endIndex); - return range.map((item) => superjson.parse<{ data: TData; timestamp: Date }>(item)); + const range = await getSetClient?.lrange(channelName, startIndex, endIndex); + return range?.map((item) => superjson.parse<{ data: TData; timestamp: Date }>(item)) ?? []; }, getSliceUntilTimeAsync: async (time: Date) => { - const length = await getSetClient.llen(channelName); + const length = await getSetClient?.llen(channelName); const items: TData[] = []; - const itemsInCollection = await getSetClient.lrange(channelName, 0, length - 1); + const itemsInCollection = await getSetClient?.lrange(channelName, 0, (length ?? 0) - 1); - for (let i = 0; i < length - 1; i++) { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const deserializedItem = superjson.parse<{ data: TData; timestamp: Date }>(itemsInCollection[i]!); + if (!itemsInCollection) return items; + + for (const item of itemsInCollection) { + if (!item) continue; + const deserializedItem = superjson.parse<{ data: TData; timestamp: Date }>(item); if (deserializedItem.timestamp < time) { continue; } @@ -338,7 +342,7 @@ export const createChannelEventHistoryOld = (channelName: string, maxElem return items; }, getLengthAsync: async () => { - return await getSetClient.llen(channelName); + return (await getSetClient?.llen(channelName)) ?? 0; }, name: channelName, }; @@ -352,14 +356,14 @@ export const createChannelWithLatestAndEvents = (channelName: string) => }); }, publishAndUpdateLastStateAsync: async (data: TData) => { - await publisher.publish(channelName, superjson.stringify(data)); - await getSetClient.set(channelName, superjson.stringify({ data, timestamp: new Date() })); + await publisher?.publish(channelName, superjson.stringify(data)); + await getSetClient?.set(channelName, superjson.stringify({ data, timestamp: new Date() })); }, setAsync: async (data: TData) => { - await getSetClient.set(channelName, superjson.stringify({ data, timestamp: new Date() })); + await getSetClient?.set(channelName, superjson.stringify({ data, timestamp: new Date() })); }, getAsync: async () => { - const data = await getSetClient.get(channelName); + const data = await getSetClient?.get(channelName); if (!data) return null; return superjson.parse<{ data: TData; timestamp: Date }>(data); @@ -380,11 +384,11 @@ type WithId = TItem & { _id: string }; export const createQueueChannel = (name: string) => { const queueChannelName = `queue:${name}`; const getDataAsync = async () => { - const data = await queueClient.get(queueChannelName); + const data = await queueClient?.get(queueChannelName); return data ? superjson.parse[]>(data) : []; }; const setDataAsync = async (data: WithId[]) => { - await queueClient.set(queueChannelName, superjson.stringify(data)); + await queueClient?.set(queueChannelName, superjson.stringify(data)); }; return { @@ -431,5 +435,5 @@ export const createQueueChannel = (name: string) => { }; export const handshakeAsync = async () => { - await getSetClient.hello(); + await getSetClient?.hello(); }; diff --git a/packages/redis/src/lib/connection.ts b/packages/redis/src/lib/connection.ts index 8b8bda3f1..972b00bb8 100644 --- a/packages/redis/src/lib/connection.ts +++ b/packages/redis/src/lib/connection.ts @@ -6,7 +6,7 @@ import { createRedisClient } from "@homarr/core/infrastructure/redis"; * @returns redis client */ export const createRedisConnection = (): RedisClient | null => { - const disableRedisLogs = process.env["DISABLE_REDIS_LOGS"] === "true"; + const disableRedisLogs = process.env.DISABLE_REDIS_LOGS === "true"; if (disableRedisLogs) { return null; diff --git a/packages/ui/src/components/password-input/password-requirements-popover.tsx b/packages/ui/src/components/password-input/password-requirements-popover.tsx index e61da060e..8ee545fb3 100644 --- a/packages/ui/src/components/password-input/password-requirements-popover.tsx +++ b/packages/ui/src/components/password-input/password-requirements-popover.tsx @@ -18,8 +18,7 @@ export const PasswordRequirementsPopover = ({ password, children }: PropsWithChi const requirements = useRequirements(); const strength = useStrength(password); const [popoverOpened, setPopoverOpened] = useState(false); - const strengthColor = - strengthColorMap.find(({ min }) => strength >= min)?.color ?? strengthColorMap[strengthColorMap.length - 1].color; + const strengthColor = strengthColorMap.find(({ min }) => strength >= min)?.color ?? "dimmed"; const checks = ( <> {requirements.map((requirement) => ( From d2ce64252cbd794189d94a1cd9732c656be56597 Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Mon, 25 May 2026 10:09:55 +0200 Subject: [PATCH 3/5] fix: revert unrelated changes (Dockerfile, Redis null-safety) --- Dockerfile | 2 + .../src/lib/channel-subscription-tracker.ts | 6 +- packages/redis/src/lib/channel.ts | 116 ++++++++---------- packages/redis/src/lib/connection.ts | 9 +- 4 files changed, 58 insertions(+), 75 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1c1388ec5..51b562f7d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,6 +15,8 @@ RUN corepack enable pnpm && pnpm install --recursive --frozen-lockfile # Copy static data as it is not part of the build COPY static-data ./static-data ARG SKIP_ENV_VALIDATION='true' +ARG CI='true' +ARG DISABLE_REDIS_LOGS='true' RUN corepack enable pnpm && pnpm build diff --git a/packages/redis/src/lib/channel-subscription-tracker.ts b/packages/redis/src/lib/channel-subscription-tracker.ts index 3c76fd5eb..02adc6897 100644 --- a/packages/redis/src/lib/channel-subscription-tracker.ts +++ b/packages/redis/src/lib/channel-subscription-tracker.ts @@ -42,7 +42,7 @@ export class ChannelSubscriptionTracker { // If there are no subscriptions to the channel, subscribe to it if (channelSubscriptions.size === 0) { logger.debug("Subscribing to redis channel", { channel: channelName }); - void this.redis?.subscribe(channelName); + void this.redis.subscribe(channelName); } logger.debug("Adding redis channel callback", { channel: channelName, id }); @@ -65,7 +65,7 @@ export class ChannelSubscriptionTracker { } logger.debug("Unsubscribing from redis channel", { channel: channelName }); - void this.redis?.unsubscribe(channelName); + void this.redis.unsubscribe(channelName); this.subscriptions.delete(channelName); }; } @@ -75,7 +75,7 @@ export class ChannelSubscriptionTracker { */ private static activateListener() { logger.debug("Activating listener"); - this.redis?.on("message", (channel, message) => { + this.redis.on("message", (channel, message) => { const channelSubscriptions = this.subscriptions.get(channel); if (!channelSubscriptions) { logger.warn("Received message on unknown channel", { channel }); diff --git a/packages/redis/src/lib/channel.ts b/packages/redis/src/lib/channel.ts index d7c8fd4f6..193f551e3 100644 --- a/packages/redis/src/lib/channel.ts +++ b/packages/redis/src/lib/channel.ts @@ -12,8 +12,6 @@ const logger = createLogger({ module: "redisChannel" }); const publisher = createRedisConnection(); const lastDataClient = createRedisConnection(); -const noopSubscription = (): (() => void) => () => undefined; - /** * Creates a new pub/sub channel. * @param name name of the channel @@ -28,16 +26,13 @@ export const createSubPubChannel = (name: string, { persist }: { persist: * @param callback callback function to be called when new data is published */ subscribe: (callback: (data: TData) => void) => { - if (persist && lastDataClient) { + if (persist) { void lastDataClient.get(lastChannelName).then((data) => { if (data) { callback(superjson.parse(data)); } }); } - if (!publisher) { - return noopSubscription(); - } return ChannelSubscriptionTracker.subscribe(channelName, (message) => { callback(superjson.parse(message)); }); @@ -47,18 +42,12 @@ export const createSubPubChannel = (name: string, { persist }: { persist: * @param data data to be published */ publishAsync: async (data: TData) => { - if (!publisher || !lastDataClient) { - return; - } if (persist) { await lastDataClient.set(lastChannelName, superjson.stringify(data)); } await publisher.publish(channelName, superjson.stringify(data)); }, getLastDataAsync: async () => { - if (!lastDataClient) { - return null; - } const data = await lastDataClient.get(lastChannelName); return data ? superjson.parse(data) : null; }, @@ -80,28 +69,28 @@ export const createListChannel = (name: string) => { * @returns an array of all items */ getAllAsync: async () => { - const items = await getSetClient?.lrange(listChannelName, 0, -1); - return items?.map((item) => superjson.parse(item)) ?? []; + const items = await getSetClient.lrange(listChannelName, 0, -1); + return items.map((item) => superjson.parse(item)); }, /** * Remove an item from the channels list by item * @param item item to remove */ removeAsync: async (item: TItem) => { - await getSetClient?.lrem(listChannelName, 0, superjson.stringify(item)); + await getSetClient.lrem(listChannelName, 0, superjson.stringify(item)); }, /** * Clear all items from the channels list */ clearAsync: async () => { - await getSetClient?.del(listChannelName); + await getSetClient.del(listChannelName); }, /** * Add an item to the channels list * @param item item to add */ addAsync: async (item: TItem) => { - await getSetClient?.lpush(listChannelName, superjson.stringify(item)); + await getSetClient.lpush(listChannelName, superjson.stringify(item)); }, }; }; @@ -117,7 +106,7 @@ export const createGetSetChannel = (name: string) => { * @returns data or null if not found */ getAsync: async () => { - const data = await getSetClient?.get(name); + const data = await getSetClient.get(name); return data ? superjson.parse(data) : null; }, /** @@ -125,13 +114,13 @@ export const createGetSetChannel = (name: string) => { * @param data data to be stored in the channel */ setAsync: async (data: TData) => { - await getSetClient?.set(name, superjson.stringify(data)); + await getSetClient.set(name, superjson.stringify(data)); }, /** * Remove data from the channel */ removeAsync: async () => { - await getSetClient?.del(name); + await getSetClient.del(name); }, }; }; @@ -151,7 +140,7 @@ export const createCacheChannel = (name: string, cacheDurationMs: number * @returns data or null if not found or expired */ getAsync: async () => { - const data = await getSetClient?.get(cacheChannelName); + const data = await getSetClient.get(cacheChannelName); if (!data) return null; const parsedData = superjson.parse<{ data: TData; timestamp: Date }>(data); @@ -167,13 +156,13 @@ export const createCacheChannel = (name: string, cacheDurationMs: number * @returns data or new data if not present or expired */ consumeAsync: async (callback: () => Promise) => { - const data = await getSetClient?.get(cacheChannelName); + const data = await getSetClient.get(cacheChannelName); const getNewDataAsync = async () => { logger.debug(`Cache miss for channel '${cacheChannelName}'`); const newData = await callback(); const result = { data: newData, timestamp: new Date() }; - await getSetClient?.set(cacheChannelName, superjson.stringify(result)); + await getSetClient.set(cacheChannelName, superjson.stringify(result)); logger.debug(`Cache updated for channel '${cacheChannelName}'`); return result; }; @@ -198,9 +187,6 @@ export const createCacheChannel = (name: string, cacheDurationMs: number * Invalidate the cache channels data. */ invalidateAsync: async () => { - if (!getSetClient) { - return; - } await getSetClient.del(cacheChannelName); }, /** @@ -208,7 +194,7 @@ export const createCacheChannel = (name: string, cacheDurationMs: number * @param data data to be stored in the cache channel */ setAsync: async (data: TData) => { - await getSetClient?.set(cacheChannelName, superjson.stringify({ data, timestamp: new Date() })); + await getSetClient.set(cacheChannelName, superjson.stringify({ data, timestamp: new Date() })); }, }; }; @@ -250,12 +236,12 @@ export const createChannelEventHistory = (channelName: string, maxElement }); }, pushAsync: async (data: TData, options = { publish: false }) => { - if (options.publish) await publisher?.publish(channelName, superjson.stringify(data)); - await getSetClient?.lpush(channelName, superjson.stringify({ data, timestamp: new Date() })); - await getSetClient?.ltrim(channelName, 0, maxElements); + if (options.publish) await publisher.publish(channelName, superjson.stringify(data)); + await getSetClient.lpush(channelName, superjson.stringify({ data, timestamp: new Date() })); + await getSetClient.ltrim(channelName, 0, maxElements); }, clearAsync: async () => { - await getSetClient?.del(channelName); + await getSetClient.del(channelName); }, /** * Returns a slice of the available data in the channel. @@ -264,19 +250,17 @@ export const createChannelEventHistory = (channelName: string, maxElement * @param endIndex End index of the slice, negative values are counted from the end, defaults at end of range. */ getSliceAsync: async (startIndex = 0, endIndex = -1) => { - const range = await getSetClient?.lrange(channelName, startIndex, endIndex); - return range?.map((item) => superjson.parse<{ data: TData; timestamp: Date }>(item)) ?? []; + const range = await getSetClient.lrange(channelName, startIndex, endIndex); + return range.map((item) => superjson.parse<{ data: TData; timestamp: Date }>(item)); }, getSliceUntilTimeAsync: async (time: Date) => { - const itemsInCollection = await getSetClient?.lrange(channelName, 0, -1); - return ( - itemsInCollection - ?.map((item) => superjson.parse<{ data: TData; timestamp: Date }>(item)) - .filter((item) => item.timestamp < time) ?? [] - ); + const itemsInCollection = await getSetClient.lrange(channelName, 0, -1); + return itemsInCollection + .map((item) => superjson.parse<{ data: TData; timestamp: Date }>(item)) + .filter((item) => item.timestamp < time); }, getLengthAsync: async () => { - return (await getSetClient?.llen(channelName)) ?? 0; + return await getSetClient.llen(channelName); }, name: channelName, }; @@ -287,11 +271,11 @@ export const createChannelEventHistory = (channelName: string, maxElement */ export const createChannelEventHistoryOld = (channelName: string, maxElements = 15) => { const popElementsOverMaxAsync = async () => { - const length = await getSetClient?.llen(channelName); - if (!length || length <= maxElements) { + const length = await getSetClient.llen(channelName); + if (length <= maxElements) { return; } - await getSetClient?.ltrim(channelName, 0, maxElements - 1); + await getSetClient.ltrim(channelName, 0, maxElements - 1); }; return { @@ -301,39 +285,37 @@ export const createChannelEventHistoryOld = (channelName: string, maxElem }); }, publishAndPushAsync: async (data: TData) => { - await publisher?.publish(channelName, superjson.stringify(data)); - await getSetClient?.lpush(channelName, superjson.stringify({ data, timestamp: new Date() })); + await publisher.publish(channelName, superjson.stringify(data)); + await getSetClient.lpush(channelName, superjson.stringify({ data, timestamp: new Date() })); await popElementsOverMaxAsync(); }, pushAsync: async (data: TData) => { - await getSetClient?.lpush(channelName, superjson.stringify({ data, timestamp: new Date() })); + await getSetClient.lpush(channelName, superjson.stringify({ data, timestamp: new Date() })); await popElementsOverMaxAsync(); }, clearAsync: async () => { - await getSetClient?.del(channelName); + await getSetClient.del(channelName); }, getLastAsync: async () => { - const length = await getSetClient?.llen(channelName); - const data = await getSetClient?.lrange(channelName, (length ?? 0) - 1, length ?? 0); - if (data?.length !== 1) return null; + const length = await getSetClient.llen(channelName); + const data = await getSetClient.lrange(channelName, length - 1, length); + if (data.length !== 1) return null; // eslint-disable-next-line @typescript-eslint/no-non-null-assertion return superjson.parse<{ data: TData; timestamp: Date }>(data[0]!); }, getSliceAsync: async (startIndex: number, endIndex: number) => { - const range = await getSetClient?.lrange(channelName, startIndex, endIndex); - return range?.map((item) => superjson.parse<{ data: TData; timestamp: Date }>(item)) ?? []; + const range = await getSetClient.lrange(channelName, startIndex, endIndex); + return range.map((item) => superjson.parse<{ data: TData; timestamp: Date }>(item)); }, getSliceUntilTimeAsync: async (time: Date) => { - const length = await getSetClient?.llen(channelName); + const length = await getSetClient.llen(channelName); const items: TData[] = []; - const itemsInCollection = await getSetClient?.lrange(channelName, 0, (length ?? 0) - 1); + const itemsInCollection = await getSetClient.lrange(channelName, 0, length - 1); - if (!itemsInCollection) return items; - - for (const item of itemsInCollection) { - if (!item) continue; - const deserializedItem = superjson.parse<{ data: TData; timestamp: Date }>(item); + for (let i = 0; i < length - 1; i++) { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const deserializedItem = superjson.parse<{ data: TData; timestamp: Date }>(itemsInCollection[i]!); if (deserializedItem.timestamp < time) { continue; } @@ -342,7 +324,7 @@ export const createChannelEventHistoryOld = (channelName: string, maxElem return items; }, getLengthAsync: async () => { - return (await getSetClient?.llen(channelName)) ?? 0; + return await getSetClient.llen(channelName); }, name: channelName, }; @@ -356,14 +338,14 @@ export const createChannelWithLatestAndEvents = (channelName: string) => }); }, publishAndUpdateLastStateAsync: async (data: TData) => { - await publisher?.publish(channelName, superjson.stringify(data)); - await getSetClient?.set(channelName, superjson.stringify({ data, timestamp: new Date() })); + await publisher.publish(channelName, superjson.stringify(data)); + await getSetClient.set(channelName, superjson.stringify({ data, timestamp: new Date() })); }, setAsync: async (data: TData) => { - await getSetClient?.set(channelName, superjson.stringify({ data, timestamp: new Date() })); + await getSetClient.set(channelName, superjson.stringify({ data, timestamp: new Date() })); }, getAsync: async () => { - const data = await getSetClient?.get(channelName); + const data = await getSetClient.get(channelName); if (!data) return null; return superjson.parse<{ data: TData; timestamp: Date }>(data); @@ -384,11 +366,11 @@ type WithId = TItem & { _id: string }; export const createQueueChannel = (name: string) => { const queueChannelName = `queue:${name}`; const getDataAsync = async () => { - const data = await queueClient?.get(queueChannelName); + const data = await queueClient.get(queueChannelName); return data ? superjson.parse[]>(data) : []; }; const setDataAsync = async (data: WithId[]) => { - await queueClient?.set(queueChannelName, superjson.stringify(data)); + await queueClient.set(queueChannelName, superjson.stringify(data)); }; return { @@ -435,5 +417,5 @@ export const createQueueChannel = (name: string) => { }; export const handshakeAsync = async () => { - await getSetClient?.hello(); + await getSetClient.hello(); }; diff --git a/packages/redis/src/lib/connection.ts b/packages/redis/src/lib/connection.ts index 972b00bb8..ba945de33 100644 --- a/packages/redis/src/lib/connection.ts +++ b/packages/redis/src/lib/connection.ts @@ -5,11 +5,10 @@ import { createRedisClient } from "@homarr/core/infrastructure/redis"; * Creates a new Redis connection * @returns redis client */ -export const createRedisConnection = (): RedisClient | null => { - const disableRedisLogs = process.env.DISABLE_REDIS_LOGS === "true"; - - if (disableRedisLogs) { - return null; +export const createRedisConnection = () => { + if (Boolean(process.env.CI) || Boolean(process.env.DISABLE_REDIS_LOGS)) { + // Return null if we are in CI as we don't want to connect to Redis + return null as unknown as RedisClient; } return createRedisClient(); From 0df64f05e54b8950592d995b5915de9859fe1b8e Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Mon, 25 May 2026 11:30:32 +0200 Subject: [PATCH 4/5] fix: remove auth session and env schema changes, keep only password requirement relaxation --- .../app/[locale]/auth/login/_login-form.tsx | 10 +----- packages/auth/adapter.ts | 13 -------- packages/auth/configuration.ts | 6 ---- packages/auth/events.ts | 2 +- packages/auth/test/adapter.spec.ts | 31 ------------------- .../core/src/infrastructure/env/schemas.ts | 31 +++++++++---------- 6 files changed, 17 insertions(+), 76 deletions(-) diff --git a/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx b/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx index 94b49fa20..71d249cf5 100644 --- a/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx +++ b/apps/nextjs/src/app/[locale]/auth/login/_login-form.tsx @@ -115,15 +115,7 @@ export const LoginForm = ({ providers, oidcClientName, isOidcAutoLoginEnabled, c {credentialInputsVisible && ( <> - - void signInAsync(credentials.provider, { - name: credentials.name, - password: credentials.password, - }), - )} - > + void signInAsync(credentials.provider, credentials))}> { - const result = db - .insert(sessions) - .values({ - sessionToken: data.sessionToken, - userId: data.userId, - expires: data.expires, - }) - .returning() - .get(); - - return result; - }, // We override the default implementation as we want to have a provider // flag in the user instead of the account to not intermingle users from different providers // eslint-disable-next-line no-restricted-syntax diff --git a/packages/auth/configuration.ts b/packages/auth/configuration.ts index 21a44a293..b0181e326 100644 --- a/packages/auth/configuration.ts +++ b/packages/auth/configuration.ts @@ -71,12 +71,6 @@ export const createConfiguration = ( const expires = expireDateAfter(env.AUTH_SESSION_EXPIRY_TIME); const sessionToken = generateSessionToken(); - - if (Number.isNaN(expires.getTime())) { - logger.error("Invalid session expiry date", { expirySeconds: env.AUTH_SESSION_EXPIRY_TIME }); - return false; - } - await adapter.createSession({ sessionToken, expires, diff --git a/packages/auth/events.ts b/packages/auth/events.ts index acd53cc8b..2593c418b 100644 --- a/packages/auth/events.ts +++ b/packages/auth/events.ts @@ -99,7 +99,7 @@ const addUserToEveryoneGroupIfNotMemberAsync = async (db: Database, userId: stri }, }); - if (dbEveryoneGroup?.id && dbEveryoneGroup.members.length === 0) { + if (dbEveryoneGroup?.members.length === 0) { await db.insert(groupMembers).values({ userId, groupId: dbEveryoneGroup.id, diff --git a/packages/auth/test/adapter.spec.ts b/packages/auth/test/adapter.spec.ts index b2b0a4ca5..d20ae3d1a 100644 --- a/packages/auth/test/adapter.spec.ts +++ b/packages/auth/test/adapter.spec.ts @@ -1,42 +1,11 @@ -/** - * @vitest-environment node - */ import { describe, expect, test } from "vitest"; -import { createId } from "@homarr/common"; import { users } from "@homarr/db/schema"; import { createDb } from "@homarr/db/test"; import { createAdapter } from "../adapter"; -import { expireDateAfter } from "../session"; describe("createAdapter should create drizzle adapter", () => { - test("createSession should insert a session row", async () => { - const db = createDb(); - const userId = createId(); - await db.insert(users).values({ id: userId, name: "demodemo", password: "hash" }); - - const adapter = createAdapter(db, "credentials"); - const sessionToken = "test-session-token"; - - const session = await adapter.createSession?.({ - sessionToken, - userId, - expires: expireDateAfter(86400), - }); - - expect(session).toMatchObject({ - sessionToken, - userId, - }); - - const storedSession = await db.query.sessions.findFirst({ - where: (table, { eq }) => eq(table.sessionToken, sessionToken), - }); - - expect(storedSession).toBeDefined(); - }); - test.each([["credentials" as const], ["ldap" as const], ["oidc" as const]])( "createAdapter getUserByEmail should return user for provider %s when this provider provided", async (provider) => { diff --git a/packages/core/src/infrastructure/env/schemas.ts b/packages/core/src/infrastructure/env/schemas.ts index 4d415b4f1..595dd37ca 100644 --- a/packages/core/src/infrastructure/env/schemas.ts +++ b/packages/core/src/infrastructure/env/schemas.ts @@ -12,26 +12,25 @@ export const createBooleanSchema = (defaultValue: boolean) => }) .default(defaultValue); -export const createDurationSchema = (defaultValue: `${number}${"s" | "m" | "h" | "d"}`) => { - const defaultMultipliers = { - s: 1, - m: 60, - h: 60 * 60, - d: 60 * 60 * 24, - } as const; - - return z +export const createDurationSchema = (defaultValue: `${number}${"s" | "m" | "h" | "d"}`) => + z .string() .regex(/^\d+[smhd]?$/) .default(defaultValue) .transform((duration) => { - const unit = duration.at(-1) as keyof typeof defaultMultipliers | undefined; - const multiplier = unit ? defaultMultipliers[unit] : undefined; - - if (multiplier) { - return Number(duration.slice(0, -1)) * multiplier; + const lastChar = duration[duration.length - 1] as "s" | "m" | "h" | "d"; + if (!isNaN(Number(lastChar))) { + return Number(defaultValue); } - return Number(duration); + const multipliers = { + s: 1, + m: 60, + h: 60 * 60, + d: 60 * 60 * 24, + }; + const numberDuration = Number(duration.slice(0, -1)); + const multiplier = multipliers[lastChar]; + + return numberDuration * multiplier; }); -}; From f1ed293b792fc9e9ce3eb57c2f4b48968245c1a7 Mon Sep 17 00:00:00 2001 From: Thomas Camlong Date: Fri, 29 May 2026 11:16:07 +0200 Subject: [PATCH 5/5] fix: address PR review feedback on password suggestions Remove redundant tests, rename requirement translations to suggestion for clearer i18n, simplify password input state and requirement display. --- e2e/onboarding.spec.ts | 31 ------------------- packages/auth/test/security.spec.ts | 8 ----- packages/translation/src/lang/ca.json | 2 +- packages/translation/src/lang/cn.json | 2 +- packages/translation/src/lang/cr.json | 2 +- packages/translation/src/lang/cs.json | 2 +- packages/translation/src/lang/da.json | 2 +- packages/translation/src/lang/de-CH.json | 2 +- packages/translation/src/lang/de.json | 2 +- packages/translation/src/lang/el.json | 2 +- packages/translation/src/lang/en-gb.json | 2 +- packages/translation/src/lang/en.json | 10 +++--- packages/translation/src/lang/es.json | 2 +- packages/translation/src/lang/et.json | 2 +- packages/translation/src/lang/fr.json | 2 +- packages/translation/src/lang/he.json | 2 +- packages/translation/src/lang/hr.json | 2 +- packages/translation/src/lang/hu.json | 2 +- packages/translation/src/lang/it.json | 2 +- packages/translation/src/lang/ja.json | 2 +- packages/translation/src/lang/ko.json | 2 +- packages/translation/src/lang/lt.json | 2 +- packages/translation/src/lang/lv.json | 2 +- packages/translation/src/lang/nl.json | 2 +- packages/translation/src/lang/no.json | 2 +- packages/translation/src/lang/pl.json | 2 +- packages/translation/src/lang/pt-br.json | 2 +- packages/translation/src/lang/pt.json | 2 +- packages/translation/src/lang/ro.json | 2 +- packages/translation/src/lang/ru.json | 2 +- packages/translation/src/lang/sk.json | 2 +- packages/translation/src/lang/sl.json | 2 +- packages/translation/src/lang/sv.json | 2 +- packages/translation/src/lang/tr.json | 2 +- packages/translation/src/lang/uk.json | 2 +- packages/translation/src/lang/vi.json | 2 +- packages/translation/src/lang/zh.json | 2 +- .../password-input/password-input.tsx | 7 ++--- .../password-input/password-requirement.tsx | 16 ++++------ .../password-requirements-popover.tsx | 2 +- packages/validation/src/user.ts | 2 +- 41 files changed, 50 insertions(+), 94 deletions(-) diff --git a/e2e/onboarding.spec.ts b/e2e/onboarding.spec.ts index 887382ea5..7e709f425 100644 --- a/e2e/onboarding.spec.ts +++ b/e2e/onboarding.spec.ts @@ -42,37 +42,6 @@ describe("Onboarding", () => { await homarrContainer.stop(); }, 60_000); - test("Credentials onboarding with special character password should be successful", async () => { - const { db, localMountPath } = await createSqliteDbFileAsync(); - const homarrContainer = await createHomarrContainer({ - mounts: { - "/appdata": localMountPath, - }, - }).start(); - - const browser = await chromium.launch(); - const context = await browser.newContext(); - const page = await context.newPage(); - const actions = new OnboardingActions(page, db); - const assertions = new OnboardingAssertions(page, db); - - await page.goto(`http://${homarrContainer.getHost()}:${homarrContainer.getMappedPort(7575)}`); - await actions.startOnboardingAsync("scratch"); - await actions.processUserStepAsync({ - username: "admin", - password: "LoveHomarr<3", - confirmPassword: "LoveHomarr<3", - }); - await actions.processSettingsStepAsync(); - - await assertions.assertFinishStepVisibleAsync(); - await assertions.assertUserAndAdminGroupInsertedAsync("admin"); - await assertions.assertDbOnboardingStepAsync("finish"); - - await browser.close(); - await homarrContainer.stop(); - }, 60_000); - test("External provider onboarding setup should be successful", async () => { // Arrange const { db, localMountPath } = await createSqliteDbFileAsync(); diff --git a/packages/auth/test/security.spec.ts b/packages/auth/test/security.spec.ts index 7b3ffd82e..fee34ec7f 100644 --- a/packages/auth/test/security.spec.ts +++ b/packages/auth/test/security.spec.ts @@ -53,12 +53,4 @@ describe("comparePasswordsAsync should compare passwords correctly", () => { // Assert expect(result).toBe(false); }); - it("should return true for passwords with special characters like LoveHomarr<3", async () => { - const password = "LoveHomarr<3"; - const hash = await hashPasswordAsync(password); - - const result = await comparePasswordsAsync(password, hash); - - expect(result).toBe(true); - }); }); diff --git a/packages/translation/src/lang/ca.json b/packages/translation/src/lang/ca.json index 6cbd7acf6..4ccc82522 100644 --- a/packages/translation/src/lang/ca.json +++ b/packages/translation/src/lang/ca.json @@ -132,7 +132,7 @@ }, "password": { "label": "Contrasenya", - "requirement": { + "suggestion": { "length": "Inclou com a mínim 8 caràcters", "lowercase": "Inclou minúscules", "uppercase": "Inclou majúscules", diff --git a/packages/translation/src/lang/cn.json b/packages/translation/src/lang/cn.json index 3a10e9210..88f801a3f 100644 --- a/packages/translation/src/lang/cn.json +++ b/packages/translation/src/lang/cn.json @@ -132,7 +132,7 @@ }, "password": { "label": "密码", - "requirement": { + "suggestion": { "length": "至少包含 8 个字符", "lowercase": "包含小写字母", "uppercase": "包含大写字母", diff --git a/packages/translation/src/lang/cr.json b/packages/translation/src/lang/cr.json index 27a4588a8..a4b260b83 100644 --- a/packages/translation/src/lang/cr.json +++ b/packages/translation/src/lang/cr.json @@ -132,7 +132,7 @@ }, "password": { "label": "crwdns26:0crwdne26:0", - "requirement": { + "suggestion": { "length": "crwdns28:0crwdne28:0", "lowercase": "crwdns30:0crwdne30:0", "uppercase": "crwdns32:0crwdne32:0", diff --git a/packages/translation/src/lang/cs.json b/packages/translation/src/lang/cs.json index 46d284ee5..30969a03d 100644 --- a/packages/translation/src/lang/cs.json +++ b/packages/translation/src/lang/cs.json @@ -132,7 +132,7 @@ }, "password": { "label": "Heslo", - "requirement": { + "suggestion": { "length": "Obsahuje alespoň 8 znaků", "lowercase": "Obsahuje malé písmeno", "uppercase": "Obsahuje velké písmeno", diff --git a/packages/translation/src/lang/da.json b/packages/translation/src/lang/da.json index 09d071783..044f7b747 100644 --- a/packages/translation/src/lang/da.json +++ b/packages/translation/src/lang/da.json @@ -132,7 +132,7 @@ }, "password": { "label": "Adgangskode", - "requirement": { + "suggestion": { "length": "Inkluderer mindst 8 tegn", "lowercase": "Inkluderer små bogstaver", "uppercase": "Inkluderer store bogstaver", diff --git a/packages/translation/src/lang/de-CH.json b/packages/translation/src/lang/de-CH.json index 024e95740..abdca6525 100644 --- a/packages/translation/src/lang/de-CH.json +++ b/packages/translation/src/lang/de-CH.json @@ -132,7 +132,7 @@ }, "password": { "label": "Passwort", - "requirement": { + "suggestion": { "length": "Enthält mindestens 8 Zeichen", "lowercase": "Enthält Kleinbuchstaben", "uppercase": "Enthält Großbuchstaben", diff --git a/packages/translation/src/lang/de.json b/packages/translation/src/lang/de.json index db0479ba6..0110618f4 100644 --- a/packages/translation/src/lang/de.json +++ b/packages/translation/src/lang/de.json @@ -132,7 +132,7 @@ }, "password": { "label": "Passwort", - "requirement": { + "suggestion": { "length": "Enthält mindestens 8 Zeichen", "lowercase": "Enthält Kleinbuchstaben", "uppercase": "Enthält Großbuchstaben", diff --git a/packages/translation/src/lang/el.json b/packages/translation/src/lang/el.json index 9c9b49876..904ac0714 100644 --- a/packages/translation/src/lang/el.json +++ b/packages/translation/src/lang/el.json @@ -132,7 +132,7 @@ }, "password": { "label": "Κωδικός", - "requirement": { + "suggestion": { "length": "", "lowercase": "Περιλαμβάνει πεζό γράμμα", "uppercase": "Περιλαμβάνει κεφαλαίο γράμμα", diff --git a/packages/translation/src/lang/en-gb.json b/packages/translation/src/lang/en-gb.json index ae6870d90..e201c1c38 100644 --- a/packages/translation/src/lang/en-gb.json +++ b/packages/translation/src/lang/en-gb.json @@ -132,7 +132,7 @@ }, "password": { "label": "Password", - "requirement": { + "suggestion": { "length": "Includes a minimum of 8 characters", "lowercase": "Includes a lower-case letter", "uppercase": "Includes an upper-case letter", diff --git a/packages/translation/src/lang/en.json b/packages/translation/src/lang/en.json index 5e742c7c4..788132aeb 100644 --- a/packages/translation/src/lang/en.json +++ b/packages/translation/src/lang/en.json @@ -133,12 +133,12 @@ "password": { "label": "Password", "suggestionsTitle": "Password suggestions", - "requirement": { + "suggestion": { "length": "At least 8 characters", - "lowercase": "Suggested: includes lowercase letter", - "uppercase": "Suggested: includes uppercase letter", - "number": "Suggested: includes number", - "special": "Suggested: includes special symbol" + "lowercase": "Includes lowercase letter", + "uppercase": "Includes uppercase letter", + "number": "Includes number", + "special": "Includes special symbol" } }, "passwordConfirm": { diff --git a/packages/translation/src/lang/es.json b/packages/translation/src/lang/es.json index cbbb17abd..23121af37 100644 --- a/packages/translation/src/lang/es.json +++ b/packages/translation/src/lang/es.json @@ -132,7 +132,7 @@ }, "password": { "label": "Contraseña", - "requirement": { + "suggestion": { "length": "Incluye al menos 8 caracteres", "lowercase": "Incluye al menos una letra minúscula", "uppercase": "Incluye al menos una letra mayúscula", diff --git a/packages/translation/src/lang/et.json b/packages/translation/src/lang/et.json index d48280e5c..987bf58db 100644 --- a/packages/translation/src/lang/et.json +++ b/packages/translation/src/lang/et.json @@ -132,7 +132,7 @@ }, "password": { "label": "", - "requirement": { + "suggestion": { "length": "", "lowercase": "", "uppercase": "", diff --git a/packages/translation/src/lang/fr.json b/packages/translation/src/lang/fr.json index a28b4718b..ae93e9622 100644 --- a/packages/translation/src/lang/fr.json +++ b/packages/translation/src/lang/fr.json @@ -132,7 +132,7 @@ }, "password": { "label": "Mot de passe", - "requirement": { + "suggestion": { "length": "Contient au moins 8 caractères", "lowercase": "Inclut une lettre minuscule", "uppercase": "Inclut une lettre majuscule", diff --git a/packages/translation/src/lang/he.json b/packages/translation/src/lang/he.json index b23563ce9..afa95ee97 100644 --- a/packages/translation/src/lang/he.json +++ b/packages/translation/src/lang/he.json @@ -132,7 +132,7 @@ }, "password": { "label": "סיסמה", - "requirement": { + "suggestion": { "length": "כולל לפחות 8 תווים", "lowercase": "אפשר אותיות קטנות", "uppercase": "אפשר אותיות גדולות", diff --git a/packages/translation/src/lang/hr.json b/packages/translation/src/lang/hr.json index 9558b4bfa..b794745df 100644 --- a/packages/translation/src/lang/hr.json +++ b/packages/translation/src/lang/hr.json @@ -132,7 +132,7 @@ }, "password": { "label": "Lozinka", - "requirement": { + "suggestion": { "length": "", "lowercase": "Uključuje mala slova", "uppercase": "Uključuje veliko slovo", diff --git a/packages/translation/src/lang/hu.json b/packages/translation/src/lang/hu.json index 44f4a8575..ef8cee25f 100644 --- a/packages/translation/src/lang/hu.json +++ b/packages/translation/src/lang/hu.json @@ -132,7 +132,7 @@ }, "password": { "label": "Jelszó", - "requirement": { + "suggestion": { "length": "Tartalmazzon legalább 8 karaktert", "lowercase": "Tartalmazzon kisbetűt", "uppercase": "Tartalmazzon nagybetűt", diff --git a/packages/translation/src/lang/it.json b/packages/translation/src/lang/it.json index 60720ad7c..1e578c856 100644 --- a/packages/translation/src/lang/it.json +++ b/packages/translation/src/lang/it.json @@ -132,7 +132,7 @@ }, "password": { "label": "Password", - "requirement": { + "suggestion": { "length": "Include almeno 8 caratteri", "lowercase": "Include lettera minuscola", "uppercase": "Include lettera maiuscola", diff --git a/packages/translation/src/lang/ja.json b/packages/translation/src/lang/ja.json index 752a3a529..73df36f45 100644 --- a/packages/translation/src/lang/ja.json +++ b/packages/translation/src/lang/ja.json @@ -132,7 +132,7 @@ }, "password": { "label": "パスワード", - "requirement": { + "suggestion": { "length": "少なくとも 8 文字以上を含む", "lowercase": "小文字を含む", "uppercase": "大文字を含む", diff --git a/packages/translation/src/lang/ko.json b/packages/translation/src/lang/ko.json index 868611bd4..09276585a 100644 --- a/packages/translation/src/lang/ko.json +++ b/packages/translation/src/lang/ko.json @@ -132,7 +132,7 @@ }, "password": { "label": "비밀번호", - "requirement": { + "suggestion": { "length": "", "lowercase": "소문자 포함", "uppercase": "대문자 포함", diff --git a/packages/translation/src/lang/lt.json b/packages/translation/src/lang/lt.json index 5b165bb86..ad5eded2c 100644 --- a/packages/translation/src/lang/lt.json +++ b/packages/translation/src/lang/lt.json @@ -132,7 +132,7 @@ }, "password": { "label": "Slaptažodis", - "requirement": { + "suggestion": { "length": "", "lowercase": "", "uppercase": "", diff --git a/packages/translation/src/lang/lv.json b/packages/translation/src/lang/lv.json index 762f7bff7..7af9291e0 100644 --- a/packages/translation/src/lang/lv.json +++ b/packages/translation/src/lang/lv.json @@ -132,7 +132,7 @@ }, "password": { "label": "Parole", - "requirement": { + "suggestion": { "length": "", "lowercase": "Ietver mazo burtu", "uppercase": "Ietver lielo burtu", diff --git a/packages/translation/src/lang/nl.json b/packages/translation/src/lang/nl.json index c8fb6c654..5cc03d9f1 100644 --- a/packages/translation/src/lang/nl.json +++ b/packages/translation/src/lang/nl.json @@ -132,7 +132,7 @@ }, "password": { "label": "Wachtwoord", - "requirement": { + "suggestion": { "length": "Bevat ten minste 8 tekens", "lowercase": "Inclusief kleine letter", "uppercase": "Inclusief hoofdletter", diff --git a/packages/translation/src/lang/no.json b/packages/translation/src/lang/no.json index 224f8c0a0..f0cfbb301 100644 --- a/packages/translation/src/lang/no.json +++ b/packages/translation/src/lang/no.json @@ -132,7 +132,7 @@ }, "password": { "label": "Passord", - "requirement": { + "suggestion": { "length": "Inkluderer minst 8 tegn", "lowercase": "Inkluderer liten bokstav", "uppercase": "Inkluderer stor bokstav", diff --git a/packages/translation/src/lang/pl.json b/packages/translation/src/lang/pl.json index c93bb30d8..de8334117 100644 --- a/packages/translation/src/lang/pl.json +++ b/packages/translation/src/lang/pl.json @@ -132,7 +132,7 @@ }, "password": { "label": "Hasło", - "requirement": { + "suggestion": { "length": "Zawiera co najmniej 8 znaków", "lowercase": "Zawiera małą literę", "uppercase": "Zawiera wielką literę", diff --git a/packages/translation/src/lang/pt-br.json b/packages/translation/src/lang/pt-br.json index 0e130afac..a505b039b 100644 --- a/packages/translation/src/lang/pt-br.json +++ b/packages/translation/src/lang/pt-br.json @@ -132,7 +132,7 @@ }, "password": { "label": "Senha", - "requirement": { + "suggestion": { "length": "Inclua pelo menos 8 caracteres", "lowercase": "Inclui letras minúsculas", "uppercase": "Inclui letras maiúsculas", diff --git a/packages/translation/src/lang/pt.json b/packages/translation/src/lang/pt.json index 4d6cbd7f0..e730bd84b 100644 --- a/packages/translation/src/lang/pt.json +++ b/packages/translation/src/lang/pt.json @@ -132,7 +132,7 @@ }, "password": { "label": "", - "requirement": { + "suggestion": { "length": "", "lowercase": "", "uppercase": "", diff --git a/packages/translation/src/lang/ro.json b/packages/translation/src/lang/ro.json index 559f78e58..fcba7b068 100644 --- a/packages/translation/src/lang/ro.json +++ b/packages/translation/src/lang/ro.json @@ -132,7 +132,7 @@ }, "password": { "label": "Parola", - "requirement": { + "suggestion": { "length": "", "lowercase": "Să includă litere mici", "uppercase": "Să includă litere mari", diff --git a/packages/translation/src/lang/ru.json b/packages/translation/src/lang/ru.json index 11d073d13..9f5b6f6e1 100644 --- a/packages/translation/src/lang/ru.json +++ b/packages/translation/src/lang/ru.json @@ -132,7 +132,7 @@ }, "password": { "label": "Пароль", - "requirement": { + "suggestion": { "length": "Содержит не менее 8 символов", "lowercase": "Содержит строчную букву", "uppercase": "Содержит заглавную букву", diff --git a/packages/translation/src/lang/sk.json b/packages/translation/src/lang/sk.json index 576aa56a3..47a41923e 100644 --- a/packages/translation/src/lang/sk.json +++ b/packages/translation/src/lang/sk.json @@ -132,7 +132,7 @@ }, "password": { "label": "Heslo", - "requirement": { + "suggestion": { "length": "Obsahuje aspoň 8 znakov", "lowercase": "Zahŕňa malé písmeno", "uppercase": "Zahŕňa veľké písmená", diff --git a/packages/translation/src/lang/sl.json b/packages/translation/src/lang/sl.json index 186e79151..112ecb12f 100644 --- a/packages/translation/src/lang/sl.json +++ b/packages/translation/src/lang/sl.json @@ -132,7 +132,7 @@ }, "password": { "label": "Geslo", - "requirement": { + "suggestion": { "length": "", "lowercase": "Vključuje male črke", "uppercase": "Vključuje velike tiskane črke", diff --git a/packages/translation/src/lang/sv.json b/packages/translation/src/lang/sv.json index 83fb869fb..b99a318a7 100644 --- a/packages/translation/src/lang/sv.json +++ b/packages/translation/src/lang/sv.json @@ -132,7 +132,7 @@ }, "password": { "label": "Lösenord", - "requirement": { + "suggestion": { "length": "Använd minst 8 tecken", "lowercase": "Använd liten bokstav", "uppercase": "Använd stor bokstav", diff --git a/packages/translation/src/lang/tr.json b/packages/translation/src/lang/tr.json index 35e29f18e..f05911e1d 100644 --- a/packages/translation/src/lang/tr.json +++ b/packages/translation/src/lang/tr.json @@ -132,7 +132,7 @@ }, "password": { "label": "Şifre", - "requirement": { + "suggestion": { "length": "En az 8 karakter içermeli", "lowercase": "Küçük harf içermeli", "uppercase": "Büyük harf içermeli", diff --git a/packages/translation/src/lang/uk.json b/packages/translation/src/lang/uk.json index c573c65ba..23a3fb284 100644 --- a/packages/translation/src/lang/uk.json +++ b/packages/translation/src/lang/uk.json @@ -132,7 +132,7 @@ }, "password": { "label": "Пароль", - "requirement": { + "suggestion": { "length": "Включає принаймні 8 символів", "lowercase": "Включає малу літеру", "uppercase": "Включає велику літеру", diff --git a/packages/translation/src/lang/vi.json b/packages/translation/src/lang/vi.json index f8f8823e1..b9a038efa 100644 --- a/packages/translation/src/lang/vi.json +++ b/packages/translation/src/lang/vi.json @@ -132,7 +132,7 @@ }, "password": { "label": "Mật khẩu", - "requirement": { + "suggestion": { "length": "Bao gồm ít nhất 8 kí tự", "lowercase": "Bao gồm chữ thường", "uppercase": "Bao gồm chữ in hoa", diff --git a/packages/translation/src/lang/zh.json b/packages/translation/src/lang/zh.json index 147db32f0..9cdd5bbbf 100644 --- a/packages/translation/src/lang/zh.json +++ b/packages/translation/src/lang/zh.json @@ -132,7 +132,7 @@ }, "password": { "label": "密碼", - "requirement": { + "suggestion": { "length": "至少包含 8 個字符", "lowercase": "包含小寫字母", "uppercase": "包含大寫字母", diff --git a/packages/ui/src/components/password-input/password-input.tsx b/packages/ui/src/components/password-input/password-input.tsx index 13141d39a..22d4a75dc 100644 --- a/packages/ui/src/components/password-input/password-input.tsx +++ b/packages/ui/src/components/password-input/password-input.tsx @@ -20,16 +20,15 @@ export const CustomPasswordInput = ({ withPasswordRequirements, ...props }: Cust }; const WithPasswordRequirements = (props: PasswordInputProps) => { - const [internalValue, setInternalValue] = useState(""); - const password = props.value ?? internalValue; + const [password, setPassword] = useState(""); const onChange = (event: ChangeEvent) => { - setInternalValue(event.currentTarget.value); + setPassword(event.currentTarget.value); props.onChange?.(event); }; return ( - + ); diff --git a/packages/ui/src/components/password-input/password-requirement.tsx b/packages/ui/src/components/password-input/password-requirement.tsx index 5031bf5c8..99d694d31 100644 --- a/packages/ui/src/components/password-input/password-requirement.tsx +++ b/packages/ui/src/components/password-input/password-requirement.tsx @@ -1,18 +1,14 @@ import { rem, Text } from "@mantine/core"; import { IconCheck, IconPoint } from "@tabler/icons-react"; -const requirementDisplay = { - met: { color: "teal", Icon: IconCheck }, - unmet: { color: "dimmed", Icon: IconPoint }, -} as const; - -const displayKey = { - true: "met", - false: "unmet", -} as const; +const getRequirementDisplay = (meets: boolean) => + ({ + true: { color: "teal", Icon: IconCheck }, + false: { color: "dimmed", Icon: IconPoint }, + })[String(meets) as "true" | "false"]; export function PasswordRequirement({ meets, label }: { meets: boolean; label: string }) { - const display = requirementDisplay[displayKey[String(meets) as "true" | "false"]]; + const display = getRequirementDisplay(meets); const Icon = display.Icon; return ( diff --git a/packages/ui/src/components/password-input/password-requirements-popover.tsx b/packages/ui/src/components/password-input/password-requirements-popover.tsx index 8ee545fb3..33cb30e42 100644 --- a/packages/ui/src/components/password-input/password-requirements-popover.tsx +++ b/packages/ui/src/components/password-input/password-requirements-popover.tsx @@ -46,7 +46,7 @@ export const PasswordRequirementsPopover = ({ password, children }: PropsWithChi }; const useRequirements = () => { - const t = useScopedI18n("user.field.password.requirement"); + const t = useScopedI18n("user.field.password.suggestion"); return passwordRequirements.map(({ check, value }) => ({ check, label: t(value) })); }; diff --git a/packages/validation/src/user.ts b/packages/validation/src/user.ts index b94e65015..824567fa6 100644 --- a/packages/validation/src/user.ts +++ b/packages/validation/src/user.ts @@ -19,7 +19,7 @@ export const passwordRequirements = [ { check: regexCheck(/[$&+,:;=?@#|'<>.^*()%!\-~`"_/\\[\]{}]/), value: "special" }, ] satisfies { check: (value: string) => boolean; - value: keyof TranslationObject["user"]["field"]["password"]["requirement"]; + value: keyof TranslationObject["user"]["field"]["password"]["suggestion"]; }[]; export const userPasswordSchema = z.string().min(8).max(255);