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 () => {
|
onSubmit={form.handleSubmit(async () => {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
const data = await signIn('credentials', {
|
const data = await signIn('credentials', {
|
||||||
|
redirect: false,
|
||||||
callbackUrl: searchParams.get('redirect') || '/',
|
callbackUrl: searchParams.get('redirect') || '/',
|
||||||
email: form.getValues('email'),
|
email: form.getValues('email'),
|
||||||
password: form.getValues('password'),
|
password: form.getValues('password'),
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ export const Register = () => {
|
|||||||
lastname: form.getValues('lastname'),
|
lastname: form.getValues('lastname'),
|
||||||
});
|
});
|
||||||
await signIn('credentials', {
|
await signIn('credentials', {
|
||||||
redirect: false,
|
callbackUrl: '/',
|
||||||
email: user.email,
|
email: user.email,
|
||||||
password: values.password,
|
password: values.password,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -5,11 +5,26 @@ import bcrypt from 'bcryptjs';
|
|||||||
export const register = async ({
|
export const register = async ({
|
||||||
password,
|
password,
|
||||||
...user
|
...user
|
||||||
}: Prisma.UserCreateInput) => {
|
}: Omit<Prisma.UserCreateInput, 'publicId'>) => {
|
||||||
const hashedPassword = await bcrypt.hash(password, 15);
|
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({
|
const newUser = prisma.user.create({
|
||||||
data: {
|
data: {
|
||||||
...user,
|
...user,
|
||||||
|
publicId: varPublicId,
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
PersonIcon,
|
PersonIcon,
|
||||||
GearIcon,
|
GearIcon,
|
||||||
ExitIcon,
|
ExitIcon,
|
||||||
|
LockClosedIcon,
|
||||||
} from '@radix-ui/react-icons';
|
} from '@radix-ui/react-icons';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
|
||||||
@@ -20,7 +21,19 @@ export const VerticalNav = () => {
|
|||||||
<PersonIcon /> Profile
|
<PersonIcon /> Profile
|
||||||
</Link>
|
</Link>
|
||||||
</li>
|
</li>
|
||||||
<li></li>
|
<li>
|
||||||
|
<details open>
|
||||||
|
<summary>
|
||||||
|
<LockClosedIcon />
|
||||||
|
Admin
|
||||||
|
</summary>
|
||||||
|
<ul>
|
||||||
|
<li>
|
||||||
|
<Link href="/admin/users">User</Link>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</details>
|
||||||
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<Link href="/settings/account">
|
<Link href="/settings/account">
|
||||||
<GearIcon />
|
<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 {
|
model User {
|
||||||
id String @id @default(uuid())
|
id String @id @default(uuid())
|
||||||
|
publicId String @unique
|
||||||
firstname String
|
firstname String
|
||||||
lastname String
|
lastname String
|
||||||
email String @unique
|
email String @unique
|
||||||
|
|||||||
Reference in New Issue
Block a user