Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat: enhance email invitation handling with SMTP configuration check

Andrej Acevski51b8c6019263
diff --git a/apps/api/src/auth.ts b/apps/api/src/auth.ts
index cfd774993..4f5513202 100644
--- a/apps/api/src/auth.ts
+++ b/apps/api/src/auth.ts
@@ -184,7 +184,7 @@ export const auth = betterAuth({
async sendInvitationEmail(data) {
const inviteLink = `${process.env.KANEO_CLIENT_URL}/auth/accept-invitation/${data.id}`;
- await sendWorkspaceInvitationEmail(
+ const result = await sendWorkspaceInvitationEmail(
data.email,
`${data.inviter.user.name} invited you to join ${data.organization.name} on Kaneo`,
{
@@ -195,6 +195,16 @@ export const auth = betterAuth({
to: data.email,
},
);
+
+ if (
+ result?.success === false &&
+ result.reason === "SMTP_NOT_CONFIGURED"
+ ) {
+ console.warn(
+ "Invitation created but email not sent due to SMTP not being configured",
+ );
+ return;
+ }
},
}),
genericOAuth({
diff --git a/apps/docs/next-env.d.ts b/apps/docs/next-env.d.ts
index 9edff1c7c..c4b7818fb 100644
--- a/apps/docs/next-env.d.ts
+++ b/apps/docs/next-env.d.ts
@@ -1,6 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
-import "./.next/types/routes.d.ts";
+import "./.next/dev/types/routes.d.ts";
// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
diff --git a/packages/email/src/send-email.tsx b/packages/email/src/send-email.tsx
index 2af9d7572..b5c76a5a9 100644
--- a/packages/email/src/send-email.tsx
+++ b/packages/email/src/send-email.tsx
@@ -38,16 +38,33 @@ export const sendMagicLinkEmail = async (
}
};
+export type EmailResult = {
+ success: boolean;
+ reason?: "SMTP_NOT_CONFIGURED";
+};
+
export const sendWorkspaceInvitationEmail = async (
to: string,
subject: string,
data: WorkspaceInvitationEmailProps,
-) => {
- const emailTemplate = await render(WorkspaceInvitationEmail({ ...data, to }));
- await transporter.sendMail({
- from: process.env.SMTP_FROM,
- to,
- subject,
- html: emailTemplate,
- });
+): Promise<EmailResult> => {
+ if (!process.env.SMTP_HOST || !process.env.SMTP_FROM) {
+ return { success: false, reason: "SMTP_NOT_CONFIGURED" };
+ }
+
+ try {
+ const emailTemplate = await render(
+ WorkspaceInvitationEmail({ ...data, to }),
+ );
+ await transporter.sendMail({
+ from: process.env.SMTP_FROM,
+ to,
+ subject,
+ html: emailTemplate,
+ });
+ return { success: true };
+ } catch (error) {
+ console.error("Error sending workspace invitation email", error);
+ throw error;
+ }
};