npm run build durch gelaufen
This commit is contained in:
@@ -41,17 +41,7 @@ async function createUserDirectly(opts: { email: string; name: string; password:
|
||||
mustChangePassword: opts.mustChangePassword ?? false,
|
||||
},
|
||||
})
|
||||
// Try better-auth API first (guaranteed correct hash format).
|
||||
// Falls back to direct DB write if API fails (e.g. admin permissions not available).
|
||||
try {
|
||||
const authHeaders = await getSanitizedHeaders()
|
||||
await auth.api.updateUser({
|
||||
body: { userId, password: opts.password },
|
||||
headers: authHeaders,
|
||||
})
|
||||
} catch {
|
||||
await createCredentialAccount(userId, opts.password)
|
||||
}
|
||||
await createCredentialAccount(userId, opts.password)
|
||||
return { id: userId }
|
||||
}
|
||||
|
||||
@@ -148,8 +138,8 @@ export const membersRouter = router({
|
||||
if (callerHasAccess) {
|
||||
const ur = memberAnyOrg.userId
|
||||
? await ctx.prisma.userRole.findUnique({
|
||||
where: { orgId_userId: { orgId: memberAnyOrg.orgId, userId: memberAnyOrg.userId } }
|
||||
})
|
||||
where: { orgId_userId: { orgId: memberAnyOrg.orgId, userId: memberAnyOrg.userId } }
|
||||
})
|
||||
: null
|
||||
return { ...memberAnyOrg, role: ur?.role ?? 'member' }
|
||||
}
|
||||
@@ -226,7 +216,7 @@ export const membersRouter = router({
|
||||
|
||||
// 1. Create the member record
|
||||
const member = await ctx.prisma.member.create({
|
||||
data: { ...rest, orgId: ctx.orgId },
|
||||
data: { ...rest, orgId: ctx.orgId } as any,
|
||||
})
|
||||
|
||||
// 2. Create a User account if a password was provided OR role is 'admin',
|
||||
@@ -256,8 +246,9 @@ export const membersRouter = router({
|
||||
where: { userId, providerId: 'credential' }
|
||||
})
|
||||
if (credAccount) {
|
||||
// Credential account exists — update the password via Better Auth
|
||||
await auth.api.updateUser({ body: { userId, password, name: input.name }, headers: authHeaders })
|
||||
// Credential account exists — update the password hash directly
|
||||
const newHash = await hashPassword(password)
|
||||
await ctx.prisma.account.update({ where: { id: credAccount.id }, data: { password: newHash } })
|
||||
} else {
|
||||
// No credential account yet — create one directly in the DB
|
||||
await createCredentialAccount(userId, password)
|
||||
@@ -292,7 +283,7 @@ export const membersRouter = router({
|
||||
|
||||
// 1. Create member record
|
||||
const member = await ctx.prisma.member.create({
|
||||
data: { ...memberData, orgId: ctx.orgId },
|
||||
data: { ...memberData, orgId: ctx.orgId } as any,
|
||||
})
|
||||
|
||||
const org = await ctx.prisma.organization.findUniqueOrThrow({
|
||||
@@ -350,7 +341,7 @@ export const membersRouter = router({
|
||||
where: { id: member.id },
|
||||
data: { userId: targetUserId }
|
||||
})
|
||||
|
||||
|
||||
if (role === 'admin') {
|
||||
await ctx.prisma.userRole.upsert({
|
||||
where: { orgId_userId: { orgId: ctx.orgId, userId: targetUserId } },
|
||||
|
||||
Reference in New Issue
Block a user