mirror of
https://github.com/lukevella/rallly.git
synced 2025-08-04 00:48:52 +02:00
Add checks for name and email
This commit is contained in:
parent
836c390180
commit
cf6c902c85
6 changed files with 61 additions and 26 deletions
|
@ -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}",
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -83,6 +83,10 @@ export const comments = router({
|
|||
{ ttl: 0 },
|
||||
);
|
||||
|
||||
if (!email) {
|
||||
continue;
|
||||
}
|
||||
|
||||
getEmailClient(watcher.user.locale ?? undefined).queueTemplate(
|
||||
"NewCommentEmail",
|
||||
{
|
||||
|
|
|
@ -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 },
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
},
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue