This commit is contained in:
Carl-Gerhard Lindesvärd
2026-01-21 08:25:32 +01:00
parent 56f1c5e894
commit a58761e8d7
29 changed files with 777 additions and 298 deletions

View File

@@ -0,0 +1,40 @@
import { z } from 'zod';
import { db } from '@openpanel/db';
import { verifyUnsubscribeToken } from '@openpanel/email';
import { createTRPCRouter, publicProcedure } from '../trpc';
export const emailRouter = createTRPCRouter({
unsubscribe: publicProcedure
.input(
z.object({
email: z.string().email(),
category: z.string(),
token: z.string(),
}),
)
.mutation(async ({ input }) => {
const { email, category, token } = input;
// Verify token
if (!verifyUnsubscribeToken(email, category, token)) {
throw new Error('Invalid unsubscribe link');
}
// Upsert the unsubscribe record
await db.emailUnsubscribe.upsert({
where: {
email_category: {
email,
category,
},
},
create: {
email,
category,
},
update: {},
});
return { success: true };
}),
});