From 8e3013ba96532cab61eb6e5fae2ce30be5e94a57 Mon Sep 17 00:00:00 2001 From: Mohamed Bassem Date: Sat, 12 Jul 2025 12:33:23 +0000 Subject: refactor: Move db interactions into the trpc routes --- packages/trpc/email.ts | 32 ++++++-------------------------- 1 file changed, 6 insertions(+), 26 deletions(-) (limited to 'packages/trpc/email.ts') diff --git a/packages/trpc/email.ts b/packages/trpc/email.ts index 1c0b8800..e69c4507 100644 --- a/packages/trpc/email.ts +++ b/packages/trpc/email.ts @@ -1,25 +1,16 @@ -import { randomBytes } from "crypto"; import { createTransport } from "nodemailer"; -import { db } from "@karakeep/db"; -import { passwordResetTokens, verificationTokens } from "@karakeep/db/schema"; import serverConfig from "@karakeep/shared/config"; -export async function sendVerificationEmail(email: string, name: string) { +export async function sendVerificationEmail( + email: string, + name: string, + token: string, +) { if (!serverConfig.email.smtp) { throw new Error("SMTP is not configured"); } - const token = randomBytes(10).toString("hex"); - const expires = new Date(Date.now() + 24 * 60 * 60 * 1000); // 24 hours - - // Store verification token - await db.insert(verificationTokens).values({ - identifier: email, - token, - expires, - }); - const transporter = createTransport({ host: serverConfig.email.smtp.host, port: serverConfig.email.smtp.port, @@ -133,22 +124,12 @@ If you weren't expecting this invitation, you can safely ignore this email. export async function sendPasswordResetEmail( email: string, name: string, - userId: string, + token: string, ) { if (!serverConfig.email.smtp) { throw new Error("SMTP is not configured"); } - const token = randomBytes(32).toString("hex"); - const expires = new Date(Date.now() + 60 * 60 * 1000); // 1 hour - - // Store password reset token - await db.insert(passwordResetTokens).values({ - userId, - token, - expires, - }); - const transporter = createTransport({ host: serverConfig.email.smtp.host, port: serverConfig.email.smtp.port, @@ -197,5 +178,4 @@ If you didn't request a password reset, please ignore this email. Your password }; await transporter.sendMail(mailOptions); - return token; } -- cgit v1.2.3-70-g09d2