mirror of
https://github.com/stack-auth/stack.git
synced 2026-06-13 21:01:21 +08:00
add timeout for sending test emails (#486)
This commit is contained in:
parent
da1b95ec3b
commit
eb618a4596
@ -3,6 +3,8 @@ import { createSmartRouteHandler } from "@/route-handlers/smart-route-handler";
|
||||
import * as schemaFields from "@stackframe/stack-shared/dist/schema-fields";
|
||||
import { adaptSchema, adminAuthTypeSchema, emailSchema, yupBoolean, yupNumber, yupObject, yupString } from "@stackframe/stack-shared/dist/schema-fields";
|
||||
import { StackAssertionError, captureError } from "@stackframe/stack-shared/dist/utils/errors";
|
||||
import { timeout } from "@stackframe/stack-shared/dist/utils/promises";
|
||||
import { Result } from "@stackframe/stack-shared/dist/utils/results";
|
||||
|
||||
export const POST = createSmartRouteHandler({
|
||||
metadata: {
|
||||
@ -35,7 +37,7 @@ export const POST = createSmartRouteHandler({
|
||||
}).defined(),
|
||||
}),
|
||||
handler: async ({ body, auth }) => {
|
||||
const result = await sendEmailWithoutRetries({
|
||||
const resultOuter = await timeout(sendEmailWithoutRetries({
|
||||
tenancyId: auth.tenancy.id,
|
||||
emailConfig: {
|
||||
type: 'standard',
|
||||
@ -50,6 +52,13 @@ export const POST = createSmartRouteHandler({
|
||||
to: body.recipient_email,
|
||||
subject: "Test Email from Stack Auth",
|
||||
text: "This is a test email from Stack Auth. If you successfully received this email, your email server configuration is working correctly.",
|
||||
}), 10000);
|
||||
|
||||
|
||||
const result = resultOuter.status === 'ok' ? resultOuter.data : Result.error({
|
||||
errorType: undefined,
|
||||
rawError: undefined,
|
||||
message: "Timed out while sending test email. Make sure the email server is running and accepting connections.",
|
||||
});
|
||||
|
||||
let errorMessage = result.status === 'error' ? result.error.message : undefined;
|
||||
|
||||
@ -82,7 +82,7 @@ async function _sendEmailWithoutRetries(options: SendEmailOptions): Promise<Resu
|
||||
runAsynchronously(async () => {
|
||||
await wait(5000);
|
||||
if (!finished) {
|
||||
captureError("email-send-timeout", new StackAssertionError("Email send took longer than 8s; maybe the email service is too slow?", {
|
||||
captureError("email-send-timeout", new StackAssertionError("Email send took longer than 5s; maybe the email service is too slow?", {
|
||||
config: options.emailConfig.type === 'shared' ? "shared" : pick(options.emailConfig, ['host', 'port', 'username', 'senderEmail', 'senderName']),
|
||||
to: options.to,
|
||||
subject: options.subject,
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
{
|
||||
"//": "THIS FILE IS AUTO-GENERATED FROM TEMPLATE. DO NOT EDIT IT DIRECTLY",
|
||||
"name": "@stackframe/react",
|
||||
"version": "2.7.18",
|
||||
"version": "2.7.19",
|
||||
"sideEffects": false,
|
||||
"main": "./dist/index.js",
|
||||
"types": "./dist/index.d.ts",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user