aboutsummaryrefslogtreecommitdiffstats
path: root/packages/trpc/email.ts
diff options
context:
space:
mode:
authorMohamed Bassem <me@mbassem.com>2025-07-12 12:33:23 +0000
committerMohamed Bassem <me@mbassem.com>2025-07-12 12:33:23 +0000
commit8e3013ba96532cab61eb6e5fae2ce30be5e94a57 (patch)
treeb101a0ac7e1218ea2562178e055044f315b0c245 /packages/trpc/email.ts
parent140311d7419fa2192e5149df8f589c3c3733a399 (diff)
downloadkarakeep-8e3013ba96532cab61eb6e5fae2ce30be5e94a57.tar.zst
refactor: Move db interactions into the trpc routes
Diffstat (limited to 'packages/trpc/email.ts')
-rw-r--r--packages/trpc/email.ts32
1 files changed, 6 insertions, 26 deletions
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;
}