49 lines
1.4 KiB
JavaScript
49 lines
1.4 KiB
JavaScript
import "dotenv/config"
|
||
import { PrismaClient } from "@prisma/client"
|
||
|
||
const prisma = new PrismaClient()
|
||
|
||
const EMAILS_TO_REMOVE = [
|
||
"cliente.demo@sistema.dev",
|
||
"luciana.prado@omnisaude.com.br",
|
||
"ricardo.matos@omnisaude.com.br",
|
||
"aline.rezende@atlasengenharia.com.br",
|
||
"joao.ramos@atlasengenharia.com.br",
|
||
"fernanda.lima@omnisaude.com.br",
|
||
"mariana.andrade@atlasengenharia.com.br",
|
||
"renanzera@gmail.com",
|
||
].map((email) => email.toLowerCase())
|
||
|
||
async function deleteAuthUserByEmail(email) {
|
||
const authUser = await prisma.authUser.findUnique({
|
||
where: { email },
|
||
select: { id: true, email: true },
|
||
})
|
||
if (!authUser) {
|
||
console.log(`ℹ️ Usuário não encontrado, ignorando: ${email}`)
|
||
return
|
||
}
|
||
|
||
await prisma.authSession.deleteMany({ where: { userId: authUser.id } })
|
||
await prisma.authAccount.deleteMany({ where: { userId: authUser.id } })
|
||
await prisma.authInvite.deleteMany({ where: { email } })
|
||
await prisma.user.deleteMany({ where: { email } })
|
||
|
||
await prisma.authUser.delete({ where: { id: authUser.id } })
|
||
console.log(`🧹 Removido: ${email}`)
|
||
}
|
||
|
||
async function main() {
|
||
for (const email of EMAILS_TO_REMOVE) {
|
||
await deleteAuthUserByEmail(email)
|
||
}
|
||
}
|
||
|
||
main()
|
||
.catch((error) => {
|
||
console.error("Falha ao remover usuários legado", error)
|
||
process.exitCode = 1
|
||
})
|
||
.finally(async () => {
|
||
await prisma.$disconnect()
|
||
})
|