diff --git a/apps/api/src/controllers/auth.ts b/apps/api/src/controllers/auth.ts index f9bdd639b..c19d7c308 100644 --- a/apps/api/src/controllers/auth.ts +++ b/apps/api/src/controllers/auth.ts @@ -39,7 +39,7 @@ export function authRoutes(fastify: FastifyInstance) { if (bearer) { const token = checkToken(bearer); if (token) { - const requester = await checkSession(token); + const requester = await checkSession(bearer); if (!requester?.isAdmin) { reply.code(401).send({ @@ -396,6 +396,10 @@ export function authRoutes(fastify: FastifyInstance) { if (token) { const { id } = request.params as { id: string }; + await prisma.notes.deleteMany({ where: { userId: id } }); + await prisma.session.deleteMany({ where: { userId: id } }); + await prisma.notifications.deleteMany({ where: { userId: id } }); + await prisma.user.delete({ where: { id }, }); diff --git a/apps/api/src/controllers/users.ts b/apps/api/src/controllers/users.ts index 978422757..1a6d2bf5e 100644 --- a/apps/api/src/controllers/users.ts +++ b/apps/api/src/controllers/users.ts @@ -101,42 +101,6 @@ export function userRoutes(fastify: FastifyInstance) { } ); - // Delete user - - // Update user - fastify.put( - "/api/v1/user/update", - - async (request: FastifyRequest, reply: FastifyReply) => { - const bearer = request.headers.authorization!.split(" ")[1]; - - const { name, email, admin, id }: any = request.body; - - if (bearer) { - const token = checkToken(bearer); - if (token) { - await prisma.user.update({ - where: { id: id }, - data: { - name, - email, - isAdmin: admin, - }, - }); - - reply.send({ - success: true, - }); - } - } else { - reply.send({ - success: false, - message: "No token provided", - }); - } - } - ); - // Mark Notification as read fastify.get( "/api/v1/user/notifcation/:id", diff --git a/apps/client/pages/admin/users/internal/index.js b/apps/client/pages/admin/users/internal/index.js index 58686734f..660edfcb2 100644 --- a/apps/client/pages/admin/users/internal/index.js +++ b/apps/client/pages/admin/users/internal/index.js @@ -205,22 +205,19 @@ export default function UserAuthPanel() { ); async function deleteUser(id) { - if (confirm("Are you sure you want to delete this user?")) { - try { - await fetch(`/api/v1/auth/user/${id}`, { - method: "DELETE", - headers: { - "Content-Type": "application/json", - Authorization: `Bearer ${token}`, - }, - }) - .then((response) => response.json()) - .then(() => { - refetch; - }); - } catch (error) { - console.log(error); - } + try { + await fetch(`/api/v1/auth/user/${id}`, { + method: "DELETE", + headers: { + Authorization: `Bearer ${token}`, + }, + }) + .then((response) => response.json()) + .then(() => { + refetch(); + }); + } catch (error) { + console.log(error); } }