refactor(dokploy): add webhook url for new users

This commit is contained in:
Mauricio Siu
2024-10-26 23:06:00 -06:00
parent fa70696c71
commit 38a72806a7

View File

@@ -10,6 +10,7 @@ import {
} from "@/server/db/schema"; } from "@/server/db/schema";
import { WEBSITE_URL } from "@/server/utils/stripe"; import { WEBSITE_URL } from "@/server/utils/stripe";
import { import {
type Auth,
IS_CLOUD, IS_CLOUD,
createAdmin, createAdmin,
createUser, createUser,
@@ -19,6 +20,7 @@ import {
getUserByToken, getUserByToken,
lucia, lucia,
luciaToken, luciaToken,
sendDiscordNotification,
sendEmailNotification, sendEmailNotification,
updateAuthById, updateAuthById,
validateRequest, validateRequest,
@@ -55,6 +57,7 @@ export const authRouter = createTRPCRouter({
const newAdmin = await createAdmin(input); const newAdmin = await createAdmin(input);
if (IS_CLOUD) { if (IS_CLOUD) {
await sendDiscordNotificationWelcome(newAdmin);
await sendVerificationEmail(newAdmin.id); await sendVerificationEmail(newAdmin.id);
return true; return true;
} }
@@ -430,3 +433,26 @@ export const sendVerificationEmail = async (authId: string) => {
return true; 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",
},
},
);
};