Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix: invitation email, email query param, invitation delete after invite successfull

Aashish-Upadhyay-1010af7079afaf8
diff --git a/components/emails/team-invitation.tsx b/components/emails/team-invitation.tsx
index c108d9d2..347cec47 100644
--- a/components/emails/team-invitation.tsx
+++ b/components/emails/team-invitation.tsx
@@ -8,22 +8,22 @@ import {
Preview,
Text,
Tailwind,
+ Section,
+ Button,
+ Hr,
} from "@react-email/components";
-
export default function TeamInvitation({
senderName,
senderEmail,
teamName,
teamId,
token,
- to,
}: {
senderName: string;
senderEmail: string;
teamName: string;
teamId: string;
token: string;
- to: string;
}) {
return (
<Html>
@@ -36,14 +36,45 @@ export default function TeamInvitation({
<span className="font-bold tracking-tighter">Papermark</span>
</Heading>
<Heading className="text-xl font-seminbold text-center p-0 mt-4 mb-8 mx-0">
- Team Invitation
+ {`Join ${teamName} on Papermark`}
</Heading>
+ <Text className="text-sm leading-6 text-black">Hey!</Text>
<Text className="text-sm leading-6 text-black">
- You are invited by {senderName}-{senderEmail} to join
- {teamName}. please click the link below to accept the invitation.
- \n\n{process.env.NEXTAUTH_URL}/api/teams/{teamId}
- /invite?email=${to}&token={token}
+ <span className="font-semibold">{senderName}</span> ({senderEmail}
+ ) has invited you to the{" "}
+ <span className="font-semibold">{teamName}</span> team on{" "}
+ <span className="font-semibold">Papermark</span>.
</Text>
+ <Section className="text-center mt-[32px] mb-[32px]">
+ <Button
+ pX={20}
+ pY={12}
+ className="bg-black rounded text-white text-xs font-semibold no-underline text-center"
+ href={`${process.env.NEXT_PUBLIC_BASE_URL}/api/teams/${teamId}/invite?token=${token}`}>
+ Join the team
+ </Button>
+ </Section>
+ <Text className="text-sm text-black">
+ or copy and paste this URL into your browser: <br />
+ {`${process.env.NEXT_PUBLIC_BASE_URL}/api/teams/${teamId}/invite?token=${token}`}
+ </Text>
+ <Text className="text-sm text-gray-400">Marc from Papermark</Text>
+ <Hr />
+ <Section className="mt-8 text-gray-400">
+ <Text className="text-xs">
+ © {new Date().getFullYear()}{" "}
+ <a
+ href="https://www.papermark.io"
+ className="no-underline text-gray-400 hover:text-gray-400 visited:text-gray-400"
+ target="_blank">
+ papermark.io
+ </a>
+ </Text>
+ <Text className="text-xs">
+ If you have any feedback or questions about this email, simply
+ reply to it. I&apos;d love to hear from you!
+ </Text>
+ </Section>
</Container>
</Body>
</Tailwind>
diff --git a/lib/emails/send-teammate-invite.ts b/lib/emails/send-teammate-invite.ts
index 3d6c0a78..b827aa24 100644
--- a/lib/emails/send-teammate-invite.ts
+++ b/lib/emails/send-teammate-invite.ts
@@ -1,4 +1,4 @@
-import TeamInvitation from "@/components/emails/team-invitation";
+import TeamInvitation from "@/components/emails/ tation";
import { sendEmail } from "@/lib/resend";
export const sendTeammateInviteEmail = async ({
@@ -25,7 +25,6 @@ export const sendTeammateInviteEmail = async ({
teamName,
teamId,
token,
- to,
}),
});
};
diff --git a/pages/api/teams/[teamId]/invite.ts b/pages/api/teams/[teamId]/invite.ts
index 628ca013..56064d9b 100644
--- a/pages/api/teams/[teamId]/invite.ts
+++ b/pages/api/teams/[teamId]/invite.ts
@@ -95,10 +95,6 @@ export default async function handle(
res.redirect(`/login?next=/api/teams/${teamId}/invite?token=${token}`);
}
- if (email !== session?.user?.email) {
- return res.status(400).json("You are not invited to the team");
- }
-
try {
const userTeam = await prisma.userTeam.findFirst({
where: {
@@ -122,6 +118,10 @@ export default async function handle(
return res.status(400).json("Invalid invitation token");
}
+ if (invitation.email !== (session?.user as CustomUser).email) {
+ return res.status(403).json("You are not invited to this team");
+ }
+
const currentTime = new Date();
if (currentTime > invitation.expires) {
return res.status(400).json("Invitation link has expired");
@@ -140,6 +140,13 @@ export default async function handle(
},
});
+ // delete the invitation record after user is successfully added to the team
+ await prisma.invitation.delete({
+ where: {
+ token,
+ },
+ });
+
return res.redirect("/documents");
} catch (error) {
errorhandler(error, res);