A modern and easy to use dashboard. 80+ integrations. 20K+ icons built in. Authentication out of the box. No YAML, drag and drop configuration.
feat: add change password form (#199)
Manuelbeb7defd3256
diff --git a/apps/nextjs/src/app/[locale]/manage/users/[userId]/_components/dangerZone.accordion.tsx b/apps/nextjs/src/app/[locale]/manage/users/[userId]/_components/dangerZone.accordion.tsxindex af9de4f1d..0484390ec 100644--- a/apps/nextjs/src/app/[locale]/manage/users/[userId]/_components/dangerZone.accordion.tsx+++ b/apps/nextjs/src/app/[locale]/manage/users/[userId]/_components/dangerZone.accordion.tsx@@ -1,15 +1,13 @@"use client";import React from "react";-import { useRouter } from "next/router";+import { useRouter } from "next/navigation";import type { RouterOutputs } from "@homarr/api";import { clientApi } from "@homarr/api/client";import { useScopedI18n } from "@homarr/translation/client";import { Button, Divider, Group, Stack, Text } from "@homarr/ui";-import { revalidatePathAction } from "~/app/revalidatePathAction";-interface DangerZoneAccordionProps {user: NonNullable<RouterOutputs["user"]["getById"]>;}@@ -19,9 +17,8 @@ export const DangerZoneAccordion = ({ user }: DangerZoneAccordionProps) => {const router = useRouter();const { mutateAsync: mutateUserDeletionAsync } =clientApi.user.delete.useMutation({- onSettled: async () => {- await router.push("/manage/users");- await revalidatePathAction("/manage/users");+ onSettled: () => {+ router.push("/manage/users");},});diff --git a/apps/nextjs/src/app/[locale]/manage/users/[userId]/_components/security.accordion.tsx b/apps/nextjs/src/app/[locale]/manage/users/[userId]/_components/security.accordion.tsxnew file mode 100644index 000000000..b95289e35--- /dev/null+++ b/apps/nextjs/src/app/[locale]/manage/users/[userId]/_components/security.accordion.tsx@@ -0,0 +1,80 @@+"use client";++import type { RouterOutputs } from "@homarr/api";+import { clientApi } from "@homarr/api/client";+import { useForm, zodResolver } from "@homarr/form";+import { showSuccessNotification } from "@homarr/notifications";+import { useI18n } from "@homarr/translation/client";+import { Button, PasswordInput, Stack, Title } from "@homarr/ui";+import { validation } from "@homarr/validation";++import { revalidatePathAction } from "~/app/revalidatePathAction";++interface SecurityAccordionComponentProps {+ user: NonNullable<RouterOutputs["user"]["getById"]>;+}++export const SecurityAccordionComponent = ({+ user,+}: SecurityAccordionComponentProps) => {+ return (+ <Stack>+ <ChangePasswordForm user={user} />+ </Stack>+ );+};++const ChangePasswordForm = ({+ user,+}: {+ user: NonNullable<RouterOutputs["user"]["getById"]>;+}) => {+ const t = useI18n();+ const { mutate, isPending } = clientApi.user.changePassword.useMutation({+ onSettled: async () => {+ await revalidatePathAction(`/manage/users/${user.id}`);+ showSuccessNotification({+ title: t(+ "management.page.user.edit.section.security.changePassword.message.passwordUpdated",+ ),+ message: "",+ });+ },+ });+ const form = useForm({+ initialValues: {+ userId: user.id,+ password: "",+ },+ validate: zodResolver(validation.user.changePassword),+ validateInputOnBlur: true,+ validateInputOnChange: true,+ });++ const handleSubmit = () => {+ mutate(form.values);+ };++ return (+ <form onSubmit={form.onSubmit(handleSubmit)}>+ <Stack>+ <Stack gap={0}>+ <Title order={5}>+ {t(+ "management.page.user.edit.section.security.changePassword.title",+ )}+ </Title>+ <PasswordInput+ label={t(+ "management.page.user.edit.section.security.changePassword.form.password.label",+ )}+ {...form.getInputProps("password")}+ />+ </Stack>+ <Button loading={isPending} type="submit" disabled={!form.isValid()}>+ {t("common.action.confirm")}+ </Button>+ </Stack>+ </form>+ );+};diff --git a/apps/nextjs/src/app/[locale]/manage/users/[userId]/page.tsx b/apps/nextjs/src/app/[locale]/manage/users/[userId]/page.tsxindex 5798a31cd..c318a6ad1 100644--- a/apps/nextjs/src/app/[locale]/manage/users/[userId]/page.tsx+++ b/apps/nextjs/src/app/[locale]/manage/users/[userId]/page.tsx@@ -20,6 +20,7 @@ import {import { api } from "~/trpc/server";import { DangerZoneAccordion } from "./_components/dangerZone.accordion";import { ProfileAccordion } from "./_components/profile.accordion";+import { SecurityAccordionComponent } from "./_components/security.accordion";interface Props {params: {@@ -80,12 +81,14 @@ export default async function EditUserPage({ params }: Props) {{t("section.security.title")}</Text></AccordionControl>- <AccordionPanel></AccordionPanel>+ <AccordionPanel>+ <SecurityAccordionComponent user={user} />+ </AccordionPanel></AccordionItem><AccordionItemstyles={{item: {- "--__item-border-color": "rgba(248,81,73,0.4)",+ borderColor: "rgba(248,81,73,0.4)",borderWidth: 4,},}}diff --git a/packages/api/src/router/user.ts b/packages/api/src/router/user.tsindex 48c3cc2df..bcc921e14 100644--- a/packages/api/src/router/user.ts+++ b/packages/api/src/router/user.ts@@ -87,6 +87,18 @@ export const userRouter = createTRPCRouter({delete: publicProcedure.input(z.string()).mutation(async ({ input, ctx }) => {await ctx.db.delete(users).where(eq(users.id, input));}),+ changePassword: publicProcedure+ .input(validation.user.changePassword)+ .mutation(async ({ ctx, input }) => {+ const salt = await createSalt();+ const hashedPassword = await hashPassword(input.password, salt);+ await ctx.db+ .update(users)+ .set({+ password: hashedPassword,+ })+ .where(eq(users.id, input.userId));+ }),});const createUser = async (diff --git a/packages/translation/src/lang/en.ts b/packages/translation/src/lang/en.tsindex d9d10c256..d7fc4ac81 100644--- a/packages/translation/src/lang/en.ts+++ b/packages/translation/src/lang/en.ts@@ -585,6 +585,17 @@ export default {},security: {title: "Security",+ changePassword: {+ title: "Change password",+ form: {+ password: {+ label: "Password",+ },+ },+ message: {+ passwordUpdated: "Updated password",+ },+ },},dangerZone: {title: "Danger zone",diff --git a/packages/validation/src/user.ts b/packages/validation/src/user.tsindex 807308d01..008905a87 100644--- a/packages/validation/src/user.ts+++ b/packages/validation/src/user.ts@@ -33,10 +33,16 @@ const editProfileSchema = z.object({.nullable(),});+const changePasswordSchema = z.object({+ userId: z.string(),+ password: passwordSchema,+});+export const userSchemas = {signIn: signInSchema,init: initUserSchema,create: createUserSchema,password: passwordSchema,editProfile: editProfileSchema,+ changePassword: changePasswordSchema,};