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 />
|
||||
|
||||
Reference in New Issue
Block a user