added users admin page + publicId
This commit is contained in:
31
apps/hub/app/(app)/admin/users/page.tsx
Normal file
31
apps/hub/app/(app)/admin/users/page.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import { PaginatedTable } from '../../../_components/PaginatedTable';
|
||||
|
||||
export default async () => {
|
||||
return (
|
||||
<PaginatedTable
|
||||
prismaModel="user"
|
||||
columns={[
|
||||
{
|
||||
header: 'ID',
|
||||
accessorKey: 'publicId',
|
||||
},
|
||||
{
|
||||
header: 'Vorname',
|
||||
accessorKey: 'firstname',
|
||||
},
|
||||
{
|
||||
header: 'Nachname',
|
||||
accessorKey: 'lastname',
|
||||
},
|
||||
{
|
||||
header: 'Email',
|
||||
accessorKey: 'email',
|
||||
},
|
||||
{
|
||||
header: 'Role',
|
||||
accessorKey: 'role',
|
||||
},
|
||||
]}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -28,6 +28,7 @@ export const Login = () => {
|
||||
onSubmit={form.handleSubmit(async () => {
|
||||
setIsLoading(true);
|
||||
const data = await signIn('credentials', {
|
||||
redirect: false,
|
||||
callbackUrl: searchParams.get('redirect') || '/',
|
||||
email: form.getValues('email'),
|
||||
password: form.getValues('password'),
|
||||
|
||||
@@ -56,7 +56,7 @@ export const Register = () => {
|
||||
lastname: form.getValues('lastname'),
|
||||
});
|
||||
await signIn('credentials', {
|
||||
redirect: false,
|
||||
callbackUrl: '/',
|
||||
email: user.email,
|
||||
password: values.password,
|
||||
});
|
||||
|
||||
@@ -5,11 +5,26 @@ import bcrypt from 'bcryptjs';
|
||||
export const register = async ({
|
||||
password,
|
||||
...user
|
||||
}: Prisma.UserCreateInput) => {
|
||||
}: Omit<Prisma.UserCreateInput, 'publicId'>) => {
|
||||
const hashedPassword = await bcrypt.hash(password, 15);
|
||||
const lastUserPublicId = await prisma.user.findFirst({
|
||||
select: {
|
||||
publicId: true,
|
||||
},
|
||||
orderBy: {
|
||||
publicId: 'desc',
|
||||
},
|
||||
});
|
||||
let varPublicId = 'VAR0000';
|
||||
if (lastUserPublicId) {
|
||||
const lastUserInt = parseInt(lastUserPublicId.publicId.replace('VAR', ''));
|
||||
varPublicId = `VAR${(lastUserInt + 1).toString().padStart(4, '0')}`;
|
||||
}
|
||||
|
||||
const newUser = prisma.user.create({
|
||||
data: {
|
||||
...user,
|
||||
publicId: varPublicId,
|
||||
password: hashedPassword,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
PersonIcon,
|
||||
GearIcon,
|
||||
ExitIcon,
|
||||
LockClosedIcon,
|
||||
} from '@radix-ui/react-icons';
|
||||
import Link from 'next/link';
|
||||
|
||||
@@ -20,7 +21,19 @@ export const VerticalNav = () => {
|
||||
<PersonIcon /> Profile
|
||||
</Link>
|
||||
</li>
|
||||
<li></li>
|
||||
<li>
|
||||
<details open>
|
||||
<summary>
|
||||
<LockClosedIcon />
|
||||
Admin
|
||||
</summary>
|
||||
<ul>
|
||||
<li>
|
||||
<Link href="/admin/users">User</Link>
|
||||
</li>
|
||||
</ul>
|
||||
</details>
|
||||
</li>
|
||||
<li>
|
||||
<Link href="/settings/account">
|
||||
<GearIcon />
|
||||
|
||||
1
packages/database/prisma/customs.sql
Normal file
1
packages/database/prisma/customs.sql
Normal file
@@ -0,0 +1 @@
|
||||
CREATE SEQUENCE user_custom_id_seq START 1;
|
||||
@@ -0,0 +1,12 @@
|
||||
/*
|
||||
Warnings:
|
||||
|
||||
- A unique constraint covering the columns `[publicId]` on the table `users` will be added. If there are existing duplicate values, this will fail.
|
||||
- Added the required column `publicId` to the `users` table without a default value. This is not possible if the table is not empty.
|
||||
|
||||
*/
|
||||
-- AlterTable
|
||||
ALTER TABLE "users" ADD COLUMN "publicId" TEXT NOT NULL;
|
||||
|
||||
-- CreateIndex
|
||||
CREATE UNIQUE INDEX "users_publicId_key" ON "users"("publicId");
|
||||
@@ -1,5 +1,6 @@
|
||||
model User {
|
||||
id String @id @default(uuid())
|
||||
publicId String @unique
|
||||
firstname String
|
||||
lastname String
|
||||
email String @unique
|
||||
|
||||
Reference in New Issue
Block a user