mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-04 21:04:37 +08:00
Don't allow creating new auth contact channels with emails that already exist
This commit is contained in:
parent
daa2aa1da0
commit
86d3eaf7f8
@ -70,6 +70,23 @@ export const contactChannelsCrudHandlers = createLazyProxy(() => createCrudHandl
|
||||
value: data.value,
|
||||
});
|
||||
|
||||
// if usedForAuth is set to true, make sure no other account uses this channel for auth
|
||||
if (data.used_for_auth) {
|
||||
const existingWithSameChannel = await tx.contactChannel.findUnique({
|
||||
where: {
|
||||
projectId_type_value_usedForAuth: {
|
||||
projectId: auth.project.id,
|
||||
type: crudContactChannelTypeToPrisma(data.type),
|
||||
value: data.value,
|
||||
usedForAuth: 'TRUE',
|
||||
},
|
||||
},
|
||||
});
|
||||
if (existingWithSameChannel) {
|
||||
throw new KnownErrors.ContactChannelAlreadyUsedForAuthBySomeoneElse(data.type);
|
||||
}
|
||||
}
|
||||
|
||||
const createdContactChannel = await tx.contactChannel.create({
|
||||
data: {
|
||||
projectId: auth.project.id,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user