Skip to content

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

refactor: update magic link email

Marc Seitz1227311e6282
diff --git a/components/emails/login-link.tsx b/components/emails/verification-link.tsx
similarity index 55%
rename from components/emails/login-link.tsx
rename to components/emails/verification-link.tsx
index 0fb1e6e0..c8445e00 100644
--- a/components/emails/login-link.tsx
+++ b/components/emails/verification-link.tsx
@@ -10,11 +10,13 @@ import {
Section,
Text,
Tailwind,
- Link,
- Hr,
} from "@react-email/components";
-const LoginLink = ({ email, url }: { email: string; url: string }) => {
+const VerificationLinkEmail = ({
+ url = "https://www.papermark.io",
+}: {
+ url: string;
+}) => {
return (
<Html>
<Head />
@@ -22,10 +24,13 @@ const LoginLink = ({ email, url }: { email: string; url: string }) => {
<Tailwind>
<Body className="mx-auto my-auto bg-white font-sans">
<Container className="mx-auto my-10 max-w-[500px] rounded border border-solid border-gray-200 px-10 py-5">
+ <Heading className="text-2xl font-normal text-center p-0 mt-4 mb-8 mx-0">
+ <span className="font-bold tracking-tighter">Papermark</span>
+ </Heading>
<Heading className="mx-0 my-7 p-0 text-center text-xl font-semibold text-black">
- Your <span className="font-bold tracking-tighter">Papermark</span>{" "}
- Login Link
+ Your Papermark Login Link
</Heading>
+
<Text className="text-sm leading-6 text-black">
Welcome to Papermark!
</Text>
@@ -33,13 +38,20 @@ const LoginLink = ({ email, url }: { email: string; url: string }) => {
Please click the magic link below to sign in to your account.
</Text>
<Section className="my-8 text-center">
- <Link
- className="bg-black rounded text-white text-xs p-2 px-6 font-semibold no-underline text-center"
+ <Button
+ className="bg-black rounded text-white text-xs font-semibold no-underline text-center"
href={url}
+ style={{ padding: "12px 20px" }}
>
Sign in
- </Link>
+ </Button>
</Section>
+ <Text className="text-sm leading-6 text-black">
+ or copy and paste this URL into your browser:
+ </Text>
+ <Text className="max-w-sm flex-wrap break-words font-medium text-purple-600 no-underline">
+ {url.replace(/^https?:\/\//, "")}
+ </Text>
</Container>
</Body>
</Tailwind>
@@ -47,4 +59,4 @@ const LoginLink = ({ email, url }: { email: string; url: string }) => {
);
};
-export default LoginLink;
+export default VerificationLinkEmail;
diff --git a/lib/emails/send-verification-request.ts b/lib/emails/send-verification-request.ts
new file mode 100644
index 00000000..e3f3f07c
--- /dev/null
+++ b/lib/emails/send-verification-request.ts
@@ -0,0 +1,16 @@
+import { sendEmail } from "@/lib/resend";
+import LoginLink from "@/components/emails/verification-link";
+
+export const sendVerificationRequestEmail = async (params: {
+ email: string;
+ url: string;
+}) => {
+ const { url, email } = params;
+ const emailTemplate = LoginLink({ url });
+ await sendEmail({
+ to: email as string,
+ subject: "Welcome to Papermark!",
+ react: emailTemplate,
+ test: process.env.NODE_ENV === "development",
+ });
+};
diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].ts
index 2d5e4b95..f3c081a6 100644
--- a/pages/api/auth/[...nextauth].ts
+++ b/pages/api/auth/[...nextauth].ts
@@ -6,8 +6,7 @@ import { CreateUserEmailProps, CustomUser } from "@/lib/types";
import { sendWelcomeEmail } from "@/lib/emails/send-welcome";
import { analytics, identifyUser, trackAnalytics } from "@/lib/analytics";
import EmailProvider from "next-auth/providers/email";
-import { sendEmail } from "@/lib/resend";
-import LoginLink from "@/components/emails/login-link";
+import { sendVerificationRequestEmail } from "@/lib/emails/send-verification-request";
const VERCEL_DEPLOYMENT = !!process.env.VERCEL_URL;
@@ -24,11 +23,15 @@ export const authOptions: NextAuthOptions = {
}),
EmailProvider({
sendVerificationRequest({ identifier, url }) {
- sendEmail({
- to: identifier,
- subject: "Your Papermark Login Link",
- react: LoginLink({ url, email: identifier }),
- });
+ if (process.env.NODE_ENV === "development") {
+ console.log(`Login link: ${url}`);
+ return;
+ } else {
+ sendVerificationRequestEmail({
+ url,
+ email: identifier,
+ });
+ }
},
}),
],