Add checks for name and email

This commit is contained in:
Luke Vella 2024-12-18 12:26:00 +00:00
parent 836c390180
commit cf6c902c85
No known key found for this signature in database
GPG key ID: 469CAD687F0D784C
6 changed files with 61 additions and 26 deletions

View file

@ -62,6 +62,10 @@ export async function POST(request: NextRequest) {
const proPricingData = await getProPricing();
if (!user.email) {
return NextResponse.redirect(new URL("/login", request.url), 401);
}
const session = await stripe.checkout.sessions.create({
success_url: absoluteUrl(
return_path ?? "/api/stripe/portal?session_id={CHECKOUT_SESSION_ID}",

View file

@ -112,7 +112,7 @@ export function ScheduledEvent() {
duration={event.duration}
location={poll.location ?? undefined}
organizer={
poll.user
poll.user && poll.user.email && poll.user.name
? { name: poll.user.name, email: poll.user.email }
: undefined
}

View file

@ -204,7 +204,7 @@ export const polls = router({
where: { id: ctx.user.id },
});
if (user) {
if (user && user.email && user.name) {
ctx.user.getEmailClient().queueTemplate("NewPollEmail", {
to: user.email,
props: {
@ -691,8 +691,8 @@ export const polls = router({
location: poll.location ?? undefined,
description: poll.description ?? undefined,
organizer: {
name: poll.user.name,
email: poll.user.email,
name: poll.user.name ?? undefined,
email: poll.user.email ?? undefined,
},
attendees: icsAttendees,
...(option.duration > 0
@ -774,27 +774,29 @@ export const polls = router({
});
}
ctx.user.getEmailClient().queueTemplate("FinalizeHostEmail", {
to: poll.user.email,
props: {
name: poll.user.name,
pollUrl: absoluteUrl(`/poll/${poll.id}`),
location: poll.location,
title: poll.title,
attendees: poll.participants
.filter((p) =>
p.votes.some(
(v) => v.optionId === input.optionId && v.type !== "no",
),
)
.map((p) => p.name),
date,
day,
dow,
time,
},
attachments: [{ filename: "event.ics", content: event.value }],
});
if (poll.user.email && poll.user.name) {
ctx.user.getEmailClient().queueTemplate("FinalizeHostEmail", {
to: poll.user.email,
props: {
name: poll.user.name,
pollUrl: absoluteUrl(`/poll/${poll.id}`),
location: poll.location,
title: poll.title,
attendees: poll.participants
.filter((p) =>
p.votes.some(
(v) => v.optionId === input.optionId && v.type !== "no",
),
)
.map((p) => p.name),
date,
day,
dow,
time,
},
attachments: [{ filename: "event.ics", content: event.value }],
});
}
for (const p of participantsToEmail) {
getEmailClient(p.locale ?? undefined).queueTemplate(

View file

@ -83,6 +83,10 @@ export const comments = router({
{ ttl: 0 },
);
if (!email) {
continue;
}
getEmailClient(watcher.user.locale ?? undefined).queueTemplate(
"NewCommentEmail",
{

View file

@ -159,6 +159,11 @@ export const participants = router({
for (const watcher of watchers) {
const email = watcher.user.email;
if (!email) {
continue;
}
const token = await createToken<DisableNotificationsPayload>(
{ watcherId: watcher.id, pollId },
{ ttl: 0 },

View file

@ -1,3 +1,4 @@
import { prisma } from "@rallly/database";
import { initTRPC, TRPCError } from "@trpc/server";
import { Ratelimit } from "@upstash/ratelimit";
import { kv } from "@vercel/kv";
@ -43,6 +44,18 @@ export const proProcedure = t.procedure.use(
});
}
const user = await prisma.user.findUnique({
where: { id: ctx.user.id },
select: { email: true, name: true },
});
if (!user?.email || !user?.name) {
throw new TRPCError({
code: "UNAUTHORIZED",
message: "User is not fully onboarded and cannot perform this action",
});
}
if (isSelfHosted) {
// Self-hosted instances don't have paid subscriptions
return next();
@ -58,7 +71,14 @@ export const proProcedure = t.procedure.use(
});
}
return next();
return next({
ctx: {
user: {
...ctx.user,
isGuest: false,
},
},
});
}),
);