mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-25 09:14:54 +10:00
make signup less error prone in db
This commit is contained in:
@@ -95,28 +95,31 @@ export default defineEventHandler(async (h3) => {
|
|||||||
{},
|
{},
|
||||||
[`internal:read`, `${userId}:write`]
|
[`internal:read`, `${userId}:write`]
|
||||||
);
|
);
|
||||||
const user = await prisma.user.create({
|
|
||||||
data: {
|
|
||||||
id: userId,
|
|
||||||
username,
|
|
||||||
displayName,
|
|
||||||
email,
|
|
||||||
profilePicture: profilePictureId,
|
|
||||||
admin: invitation.isAdmin,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const hash = await createHashArgon2(password);
|
const hash = await createHashArgon2(password);
|
||||||
await prisma.linkedAuthMec.create({
|
const [linkMec] = await prisma.$transaction([
|
||||||
data: {
|
prisma.linkedAuthMec.create({
|
||||||
mec: AuthMec.Simple,
|
data: {
|
||||||
credentials: {},
|
mec: AuthMec.Simple,
|
||||||
userId: user.id,
|
credentials: {},
|
||||||
password: hash,
|
password: hash,
|
||||||
},
|
user: {
|
||||||
});
|
create: {
|
||||||
|
id: userId,
|
||||||
|
username,
|
||||||
|
displayName,
|
||||||
|
email,
|
||||||
|
profilePicture: profilePictureId,
|
||||||
|
admin: invitation.isAdmin,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
select: {
|
||||||
|
user: true,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
prisma.invitation.delete({ where: { id: invitationId } }),
|
||||||
|
]);
|
||||||
|
|
||||||
await prisma.invitation.delete({ where: { id: invitationId } });
|
return linkMec.user;
|
||||||
|
|
||||||
return user;
|
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user