From 38a72806a708e48b3ab6a3086a499aa18d844e02 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 26 Oct 2024 23:06:00 -0600 Subject: [PATCH] refactor(dokploy): add webhook url for new users --- apps/dokploy/server/api/routers/auth.ts | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/apps/dokploy/server/api/routers/auth.ts b/apps/dokploy/server/api/routers/auth.ts index 73869123..8ba5eb24 100644 --- a/apps/dokploy/server/api/routers/auth.ts +++ b/apps/dokploy/server/api/routers/auth.ts @@ -10,6 +10,7 @@ import { } from "@/server/db/schema"; import { WEBSITE_URL } from "@/server/utils/stripe"; import { + type Auth, IS_CLOUD, createAdmin, createUser, @@ -19,6 +20,7 @@ import { getUserByToken, lucia, luciaToken, + sendDiscordNotification, sendEmailNotification, updateAuthById, validateRequest, @@ -55,6 +57,7 @@ export const authRouter = createTRPCRouter({ const newAdmin = await createAdmin(input); if (IS_CLOUD) { + await sendDiscordNotificationWelcome(newAdmin); await sendVerificationEmail(newAdmin.id); return true; } @@ -430,3 +433,26 @@ export const sendVerificationEmail = async (authId: string) => { return true; }; + +export const sendDiscordNotificationWelcome = async (newAdmin: Auth) => { + await sendDiscordNotification( + { + webhookUrl: process.env.DISCORD_WEBHOOK_URL || "", + }, + { + title: "✅ New User Registered", + color: 0x00ff00, + fields: [ + { + name: "Email", + value: newAdmin.email, + inline: true, + }, + ], + timestamp: newAdmin.createdAt, + footer: { + text: "Dokploy User Registration Notification", + }, + }, + ); +};