Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.
feat: add block list
Marc Seitz6a1ee7659d25
diff --git a/lib/edge-config/blacklist.ts b/lib/edge-config/blacklist.tsnew file mode 100644index 00000000..ca6a5182--- /dev/null+++ b/lib/edge-config/blacklist.ts@@ -0,0 +1,21 @@+import { get } from "@vercel/edge-config";++export const isBlacklistedEmail = async (email: string) => {+ if (!process.env.EDGE_CONFIG) {+ return false;+ }++ let blacklistedEmails: string[] = [];+ try {+ const result = await get("emails");+ // Make sure we only use string arrays+ blacklistedEmails = Array.isArray(result)+ ? result.filter((item): item is string => typeof item === "string")+ : [];+ } catch (e) {+ // Already initialized as empty array+ }++ if (blacklistedEmails.length === 0) return false;+ return new RegExp(blacklistedEmails.join("|"), "i").test(email);+};diff --git a/lib/types.ts b/lib/types.tsindex 90a685a6..35fc953a 100644--- a/lib/types.ts+++ b/lib/types.ts@@ -275,6 +275,11 @@ export type AnalyticsEvents =event: "Stripe Billing Portal Clicked";teamId: string;action?: string;+ }+ | {+ event: "User Sign In Attempted";+ email: string | undefined;+ userId: string;};export interface Team {diff --git a/pages/api/auth/[...nextauth].ts b/pages/api/auth/[...nextauth].tsindex 42bb9917..ce4bd251 100644--- a/pages/api/auth/[...nextauth].ts+++ b/pages/api/auth/[...nextauth].ts@@ -6,6 +6,7 @@ import GoogleProvider from "next-auth/providers/google";import LinkedInProvider from "next-auth/providers/linkedin";import { identifyUser, trackAnalytics } from "@/lib/analytics";+import { isBlacklistedEmail } from "@/lib/edge-config/blacklist";import { sendVerificationRequestEmail } from "@/lib/emails/send-verification-request";import { sendWelcomeEmail } from "@/lib/emails/send-welcome";import hanko from "@/lib/hanko";@@ -95,6 +96,19 @@ export const authOptions: NextAuthOptions = {},},callbacks: {+ signIn: async ({ user }) => {+ if (!user.email || (await isBlacklistedEmail(user.email))) {+ await identifyUser(user.email ?? user.id);+ await trackAnalytics({+ event: "User Sign In Attempted",+ email: user.email ?? undefined,+ userId: user.id,+ });+ return false;+ }+ return true;+ },+jwt: async (params) => {const { token, user, trigger } = params;if (!token.email) {