mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-30 21:01:54 +08:00
fix: return 409 instead of 500 when signing up with duplicate email (#1637)
This commit is contained in:
parent
433d4dcc96
commit
5b9fd1695f
@ -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,
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -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>,
|
||||
},
|
||||
}
|
||||
|
||||
@ -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>,
|
||||
},
|
||||
}
|
||||
|
||||
@ -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>,
|
||||
},
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user