fix: return 409 instead of 500 when signing up with duplicate email (#1637)

This commit is contained in:
Konsti Wohlwend 2026-06-22 17:29:08 -07:00 committed by GitHub
parent 433d4dcc96
commit 5b9fd1695f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 27 additions and 21 deletions

View File

@ -69,7 +69,7 @@ export const POST = createSmartRouteHandler({
primary_email_auth_enabled: true,
password,
},
[KnownErrors.UserWithEmailAlreadyExists],
[KnownErrors.UserWithEmailAlreadyExists, KnownErrors.ContactChannelAlreadyUsedForAuthBySomeoneElse],
buildSignUpRuleOptions({
authMethod: 'password',
oauthProvider: null,

View File

@ -49,6 +49,7 @@ function catchError(error: unknown, requestId: string): StatusError {
}
if (StatusError.isStatusError(error)) return error;
captureError(`route-handler`, error);
return new InternalServerError(error, requestId);
}

View File

@ -321,15 +321,16 @@ it("should not allow duplicate accounts with same normalized email", async ({ ex
NiceResponse {
"status": 409,
"body": {
"code": "USER_EMAIL_ALREADY_EXISTS",
"code": "CONTACT_CHANNEL_ALREADY_USED_FOR_AUTH_BY_SOMEONE_ELSE",
"details": {
"email": "duplicate.test-<stripped UUID>@example.com",
"contact_channel_value": "duplicate.test-<stripped UUID>@example.com",
"type": "email",
"would_work_if_email_was_verified": false,
},
"error": "A user with email \\"duplicate.test-<stripped UUID>@example.com\\" already exists.",
"error": "This email \\"(duplicate.test-<stripped UUID>@example.com)\\" is already used for authentication by another account.",
},
"headers": Headers {
"x-stack-known-error": "USER_EMAIL_ALREADY_EXISTS",
"x-stack-known-error": "CONTACT_CHANNEL_ALREADY_USED_FOR_AUTH_BY_SOMEONE_ELSE",
<some fields may have been hidden>,
},
}

View File

@ -140,15 +140,16 @@ it("should not allow signing up with an e-mail that already exists", async ({ ex
NiceResponse {
"status": 409,
"body": {
"code": "USER_EMAIL_ALREADY_EXISTS",
"code": "CONTACT_CHANNEL_ALREADY_USED_FOR_AUTH_BY_SOMEONE_ELSE",
"details": {
"email": "default-mailbox--<stripped UUID>@stack-generated.example.com",
"contact_channel_value": "default-mailbox--<stripped UUID>@stack-generated.example.com",
"type": "email",
"would_work_if_email_was_verified": false,
},
"error": "A user with email \\"default-mailbox--<stripped UUID>@stack-generated.example.com\\" already exists.",
"error": "This email \\"(default-mailbox--<stripped UUID>@stack-generated.example.com)\\" is already used for authentication by another account.",
},
"headers": Headers {
"x-stack-known-error": "USER_EMAIL_ALREADY_EXISTS",
"x-stack-known-error": "CONTACT_CHANNEL_ALREADY_USED_FOR_AUTH_BY_SOMEONE_ELSE",
<some fields may have been hidden>,
},
}

View File

@ -1642,15 +1642,16 @@ describe("with server access", () => {
NiceResponse {
"status": 409,
"body": {
"code": "USER_EMAIL_ALREADY_EXISTS",
"code": "CONTACT_CHANNEL_ALREADY_USED_FOR_AUTH_BY_SOMEONE_ELSE",
"details": {
"email": "default-mailbox--<stripped UUID>@stack-generated.example.com",
"contact_channel_value": "default-mailbox--<stripped UUID>@stack-generated.example.com",
"type": "email",
"would_work_if_email_was_verified": false,
},
"error": "A user with email \\"default-mailbox--<stripped UUID>@stack-generated.example.com\\" already exists.",
"error": "This email \\"(default-mailbox--<stripped UUID>@stack-generated.example.com)\\" is already used for authentication by another account.",
},
"headers": Headers {
"x-stack-known-error": "USER_EMAIL_ALREADY_EXISTS",
"x-stack-known-error": "CONTACT_CHANNEL_ALREADY_USED_FOR_AUTH_BY_SOMEONE_ELSE",
<some fields may have been hidden>,
},
}
@ -2395,15 +2396,16 @@ describe("with server access", () => {
NiceResponse {
"status": 409,
"body": {
"code": "USER_EMAIL_ALREADY_EXISTS",
"code": "CONTACT_CHANNEL_ALREADY_USED_FOR_AUTH_BY_SOMEONE_ELSE",
"details": {
"email": "default-mailbox--<stripped UUID>@stack-generated.example.com",
"contact_channel_value": "default-mailbox--<stripped UUID>@stack-generated.example.com",
"type": "email",
"would_work_if_email_was_verified": false,
},
"error": "A user with email \\"default-mailbox--<stripped UUID>@stack-generated.example.com\\" already exists.",
"error": "This email \\"(default-mailbox--<stripped UUID>@stack-generated.example.com)\\" is already used for authentication by another account.",
},
"headers": Headers {
"x-stack-known-error": "USER_EMAIL_ALREADY_EXISTS",
"x-stack-known-error": "CONTACT_CHANNEL_ALREADY_USED_FOR_AUTH_BY_SOMEONE_ELSE",
<some fields may have been hidden>,
},
}
@ -2458,15 +2460,16 @@ describe("with server access", () => {
NiceResponse {
"status": 409,
"body": {
"code": "USER_EMAIL_ALREADY_EXISTS",
"code": "CONTACT_CHANNEL_ALREADY_USED_FOR_AUTH_BY_SOMEONE_ELSE",
"details": {
"email": "default-mailbox--<stripped UUID>@stack-generated.example.com",
"contact_channel_value": "default-mailbox--<stripped UUID>@stack-generated.example.com",
"type": "email",
"would_work_if_email_was_verified": false,
},
"error": "A user with email \\"default-mailbox--<stripped UUID>@stack-generated.example.com\\" already exists.",
"error": "This email \\"(default-mailbox--<stripped UUID>@stack-generated.example.com)\\" is already used for authentication by another account.",
},
"headers": Headers {
"x-stack-known-error": "USER_EMAIL_ALREADY_EXISTS",
"x-stack-known-error": "CONTACT_CHANNEL_ALREADY_USED_FOR_AUTH_BY_SOMEONE_ELSE",
<some fields may have been hidden>,
},
}