-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeleteUser.ts
33 lines (26 loc) · 932 Bytes
/
deleteUser.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
"use server"
import { db } from "@/lib/db";
import { auth } from "../auth";
import { getUserByEmail,getUserById } from "./user";
export const deleteUser = async (
userId : number
) => {
try {
const session = await auth();
const authorId = session?.id;
// Obtenção do usuário pelo e-mail
const user = await getUserById(parseInt(authorId));
if (!user) {
throw new Error('Usuário não encontrado.');
}
// Atualizando as informações do usuário no banco de dados
const updatedUser = await db.user.delete({
where: { id: userId } // Atualiza o usuário baseado no ID
});
// console.log('Informações atualizadas:', updatedUser);
return { success: "Conta apagada com sucesso!", error: null };
} catch (error) {
console.error('Erro ao atualizar as informações:', error);
return { success: null, error: "Erro ao atualizar as informações." };
}
};