feat: add user management (#134)
This commit is contained in:
@@ -3,8 +3,9 @@ import "server-only";
|
||||
import { TRPCError } from "@trpc/server";
|
||||
|
||||
import { createSalt, hashPassword } from "@homarr/auth";
|
||||
import { createId, schema } from "@homarr/db";
|
||||
import { validation } from "@homarr/validation";
|
||||
import { createId, db, eq, schema } from "@homarr/db";
|
||||
import { users } from "@homarr/db/schema/sqlite";
|
||||
import { validation, z } from "@homarr/validation";
|
||||
|
||||
import { createTRPCRouter, publicProcedure } from "../trpc";
|
||||
|
||||
@@ -36,4 +37,43 @@ export const userRouter = createTRPCRouter({
|
||||
salt,
|
||||
});
|
||||
}),
|
||||
getAll: publicProcedure.query(async () => {
|
||||
return db.query.users.findMany({
|
||||
columns: {
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
emailVerified: true,
|
||||
image: true,
|
||||
},
|
||||
});
|
||||
}),
|
||||
getById: publicProcedure
|
||||
.input(z.object({ userId: z.string() }))
|
||||
.query(async ({ input }) => {
|
||||
return db.query.users.findFirst({
|
||||
columns: {
|
||||
id: true,
|
||||
name: true,
|
||||
email: true,
|
||||
emailVerified: true,
|
||||
image: true,
|
||||
},
|
||||
where: eq(users.id, input.userId),
|
||||
});
|
||||
}),
|
||||
create: publicProcedure
|
||||
.input(
|
||||
z.object({
|
||||
name: z.string(),
|
||||
email: z.string().email().or(z.string().length(0).optional()),
|
||||
}),
|
||||
)
|
||||
.mutation(async ({ input }) => {
|
||||
await db.insert(users).values({
|
||||
id: createId(),
|
||||
name: input.name,
|
||||
email: input.email,
|
||||
});
|
||||
}),
|
||||
});
|
||||
|
||||
@@ -147,6 +147,8 @@ export default {
|
||||
saveChanges: "Save changes",
|
||||
cancel: "Cancel",
|
||||
confirm: "Confirm",
|
||||
previous: "Previous",
|
||||
next: "Next",
|
||||
},
|
||||
multiSelect: {
|
||||
placeholder: "Pick one or more values",
|
||||
@@ -394,6 +396,50 @@ export default {
|
||||
},
|
||||
},
|
||||
},
|
||||
user: {
|
||||
list: {
|
||||
metaTitle: "Manage users",
|
||||
title: "Users",
|
||||
},
|
||||
edit: {
|
||||
metaTitle: "Edit user {username}",
|
||||
},
|
||||
create: {
|
||||
metaTitle: "Create user",
|
||||
title: "Create new user",
|
||||
step: {
|
||||
personalInformation: {
|
||||
label: "Personal information",
|
||||
field: {
|
||||
username: {
|
||||
label: "Username",
|
||||
},
|
||||
email: {
|
||||
label: "E-Mail",
|
||||
},
|
||||
},
|
||||
},
|
||||
preferences: {
|
||||
label: "Preferences",
|
||||
description: "Coming soon",
|
||||
},
|
||||
permissions: {
|
||||
label: "Permissions",
|
||||
description: "Coming soon",
|
||||
},
|
||||
review: {
|
||||
label: "Review",
|
||||
},
|
||||
completed: {
|
||||
title: "User created",
|
||||
},
|
||||
},
|
||||
buttons: {
|
||||
createAnother: "Create another user",
|
||||
return: "Return to the user list",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
"dependencies": {
|
||||
"@mantine/core": "^7.5.3",
|
||||
"@mantine/dates": "^7.5.3",
|
||||
"@tabler/icons-react": "^2.47.0"
|
||||
"@tabler/icons-react": "^2.47.0",
|
||||
"mantine-react-table": "2.0.0-alpha.17"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
@import "@mantine/core/styles.css";
|
||||
@import "@mantine/dates/styles.css";
|
||||
@import "mantine-react-table/styles.css";
|
||||
|
||||
Reference in New Issue
Block a user