feat: refine admin access management

This commit is contained in:
Esdras Renan 2025-10-18 01:32:19 -03:00
parent dded6d1927
commit a69d37a672
9 changed files with 265 additions and 83 deletions

View file

@ -0,0 +1,49 @@
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()
})