fix(auth): sincroniza User e AuthUser com mesmo ID
- Aceitar convite: cria User com mesmo ID do AuthUser - Criar usuario admin: usa ID do AuthUser no upsert do User - Garante sincronismo entre tabelas de auth e dominio 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
7f63120336
commit
3bfc5793f1
2 changed files with 19 additions and 1 deletions
|
|
@ -204,7 +204,7 @@ export async function POST(request: Request) {
|
||||||
})
|
})
|
||||||
|
|
||||||
const createdDomainUser = await tx.user.upsert({
|
const createdDomainUser = await tx.user.upsert({
|
||||||
where: { email },
|
where: { id: createdAuthUser.id },
|
||||||
update: {
|
update: {
|
||||||
name,
|
name,
|
||||||
role: userRole,
|
role: userRole,
|
||||||
|
|
@ -213,6 +213,7 @@ export async function POST(request: Request) {
|
||||||
managerId: managerRecord?.id ?? null,
|
managerId: managerRecord?.id ?? null,
|
||||||
},
|
},
|
||||||
create: {
|
create: {
|
||||||
|
id: createdAuthUser.id,
|
||||||
name,
|
name,
|
||||||
email,
|
email,
|
||||||
role: userRole,
|
role: userRole,
|
||||||
|
|
|
||||||
|
|
@ -157,6 +157,23 @@ export async function POST(request: Request, context: { params: Promise<{ token:
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Criar registro na tabela User (dominio) com mesmo ID do AuthUser
|
||||||
|
try {
|
||||||
|
await prisma.user.upsert({
|
||||||
|
where: { id: user.id },
|
||||||
|
update: { role: role.toUpperCase() as "ADMIN" | "AGENT" | "COLLABORATOR", name },
|
||||||
|
create: {
|
||||||
|
id: user.id,
|
||||||
|
tenantId,
|
||||||
|
email: invite.email,
|
||||||
|
name,
|
||||||
|
role: role.toUpperCase() as "ADMIN" | "AGENT" | "COLLABORATOR",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
} catch (err) {
|
||||||
|
console.warn("Falha ao criar User de dominio", err)
|
||||||
|
}
|
||||||
|
|
||||||
const updatedInvite = await prisma.authInvite.update({
|
const updatedInvite = await prisma.authInvite.update({
|
||||||
where: { id: invite.id },
|
where: { id: invite.id },
|
||||||
data: {
|
data: {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue