Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

add "user_" prefix, update login with Framer

Steven Tey3a3b6c1e9175
diff --git a/apps/web/app/partners.dub.co/(auth)/(default)/page.tsx b/apps/web/app/partners.dub.co/(auth)/(default)/page.tsx
deleted file mode 100644
index d8a8090461..0000000000
--- a/apps/web/app/partners.dub.co/(auth)/(default)/page.tsx
+++ /dev/null
@@ -1,10 +0,0 @@
-import { constructMetadata } from "@dub/utils";
-import { PartnersPageClient } from "./page-client";
-
-export const metadata = constructMetadata({
- noIndex: true,
-});
-
-export default function PartnersPage() {
- return <PartnersPageClient />;
-}
diff --git a/apps/web/app/partners.dub.co/(auth)/(default)/page-client.tsx b/apps/web/app/partners.dub.co/(auth)/(default)/waitlist/page-client.tsx
similarity index 69%
rename from apps/web/app/partners.dub.co/(auth)/(default)/page-client.tsx
rename to apps/web/app/partners.dub.co/(auth)/(default)/waitlist/page-client.tsx
index a12f2c2b07..c1bdc61838 100644
--- a/apps/web/app/partners.dub.co/(auth)/(default)/page-client.tsx
+++ b/apps/web/app/partners.dub.co/(auth)/(default)/waitlist/page-client.tsx
@@ -3,9 +3,12 @@
import { buttonVariants } from "@dub/ui";
import { LinkedIn, Twitter } from "@dub/ui/icons";
import { cn } from "@dub/utils";
+import { signOut, useSession } from "next-auth/react";
import Link from "next/link";
-export function PartnersPageClient() {
+export function PartnersWaitlistPageClient() {
+ const { data: session } = useSession();
+
return (
<div className="mx-auto my-10 w-full max-w-md md:mt-16 lg:mt-20">
<div className="rounded-lg border border-neutral-200 bg-white p-4 py-6 sm:p-8 sm:pb-10">
@@ -46,6 +49,24 @@ export function PartnersPageClient() {
dubinc
</Link>
</div>
+ <div className="mt-8 text-[0.8rem] text-neutral-500">
+ <p>
+ You're logged in as{" "}
+ {session?.user?.email ? (
+ <span className="font-medium text-neutral-700">
+ {session.user.email}
+ </span>
+ ) : (
+ <span className="inline-flex h-2 w-48 rounded-md bg-neutral-100" />
+ )}
+ </p>
+ <button
+ onClick={() => signOut()}
+ className="underline underline-offset-2 hover:text-neutral-800"
+ >
+ Sign out to switch accounts
+ </button>
+ </div>
</div>
</div>
);
diff --git a/apps/web/app/partners.dub.co/(auth)/(default)/waitlist/page.tsx b/apps/web/app/partners.dub.co/(auth)/(default)/waitlist/page.tsx
new file mode 100644
index 0000000000..05cbe9ae34
--- /dev/null
+++ b/apps/web/app/partners.dub.co/(auth)/(default)/waitlist/page.tsx
@@ -0,0 +1,10 @@
+import { constructMetadata } from "@dub/utils";
+import { PartnersWaitlistPageClient } from "./page-client";
+
+export const metadata = constructMetadata({
+ noIndex: true,
+});
+
+export default function PartnersWaitlistPage() {
+ return <PartnersWaitlistPageClient />;
+}
diff --git a/apps/web/lib/actions/create-user-account.ts b/apps/web/lib/actions/create-user-account.ts
index 0546e610e5..3bfdef4efd 100644
--- a/apps/web/lib/actions/create-user-account.ts
+++ b/apps/web/lib/actions/create-user-account.ts
@@ -3,7 +3,7 @@
import { ratelimit } from "@/lib/upstash";
import { prisma } from "@dub/prisma";
import { flattenValidationErrors } from "next-safe-action";
-import { getIP } from "../api/utils";
+import { createId, getIP } from "../api/utils";
import { hashPassword } from "../auth/password";
import z from "../zod";
import { signUpSchema } from "../zod/schemas/auth";
@@ -60,6 +60,7 @@ export const createUserAccountAction = actionClient
if (!user) {
await prisma.user.create({
data: {
+ id: createId({ prefix: "user_" }),
email,
passwordHash: await hashPassword(password),
emailVerified: new Date(),
diff --git a/apps/web/lib/api/utils.ts b/apps/web/lib/api/utils.ts
index d1d0ead74d..c917ed7a74 100644
--- a/apps/web/lib/api/utils.ts
+++ b/apps/web/lib/api/utils.ts
@@ -53,6 +53,7 @@ export const getIP = () => {
};
const prefixes = [
+ "user_",
"link_",
"tag_",
"dom_",
diff --git a/apps/web/lib/auth/options.ts b/apps/web/lib/auth/options.ts
index 54cbe5d3ec..191ff8c7ab 100644
--- a/apps/web/lib/auth/options.ts
+++ b/apps/web/lib/auth/options.ts
@@ -1,10 +1,11 @@
-import { isBlacklistedEmail } from "@/lib/edge-config";
+import { isBlacklistedEmail, updateConfig } from "@/lib/edge-config";
import jackson from "@/lib/jackson";
import { subscribe } from "@/lib/resend";
import { isStored, storage } from "@/lib/storage";
import { UserProps } from "@/lib/types";
import { ratelimit } from "@/lib/upstash";
import { prisma } from "@dub/prisma";
+import { PrismaClient } from "@dub/prisma/client";
import { PrismaAdapter } from "@next-auth/prisma-adapter";
import { waitUntil } from "@vercel/functions";
import { sendEmail } from "emails";
@@ -17,6 +18,7 @@ import CredentialsProvider from "next-auth/providers/credentials";
import EmailProvider from "next-auth/providers/email";
import GithubProvider from "next-auth/providers/github";
import GoogleProvider from "next-auth/providers/google";
+import { createId } from "../api/utils";
import { completeProgramApplications } from "../partners/complete-program-applications";
import { FRAMER_API_HOST } from "./constants";
import {
@@ -28,6 +30,20 @@ import { trackLead } from "./track-lead";
const VERCEL_DEPLOYMENT = !!process.env.VERCEL_URL;
+const CustomPrismaAdapter = (p: PrismaClient) => {
+ return {
+ ...PrismaAdapter(p),
+ createUser: async (data: any) => {
+ return p.user.create({
+ data: {
+ ...data,
+ id: createId({ prefix: "user_" }),
+ },
+ });
+ },
+ };
+};
+
export const authOptions: NextAuthOptions = {
providers: [
EmailProvider({
@@ -82,6 +98,7 @@ export const authOptions: NextAuthOptions = {
if (!existingUser) {
existingUser = await prisma.user.create({
data: {
+ id: createId({ prefix: "user_" }),
email: profile.email,
name: `${profile.firstName || ""} ${
profile.lastName || ""
@@ -152,6 +169,7 @@ export const authOptions: NextAuthOptions = {
if (!existingUser) {
existingUser = await prisma.user.create({
data: {
+ id: createId({ prefix: "user_" }),
email: userInfo.email,
name: `${userInfo.firstName || ""} ${
userInfo.lastName || ""
@@ -283,7 +301,7 @@ export const authOptions: NextAuthOptions = {
},
],
// @ts-ignore
- adapter: PrismaAdapter(prisma),
+ adapter: CustomPrismaAdapter(prisma),
session: { strategy: "jwt" },
cookies: {
sessionToken: {
@@ -316,35 +334,6 @@ export const authOptions: NextAuthOptions = {
return false;
}
- // Login with Framer
- if (account?.provider === "framer") {
- const userFound = await prisma.user.findUnique({
- where: {
- email: user.email,
- },
- include: {
- accounts: true,
- },
- });
-
- // account doesn't exist, let the user sign in
- if (!userFound) {
- return true;
- }
-
- const otherAccounts = userFound?.accounts.filter(
- (account) => account.provider !== "framer",
- );
-
- // we don't allow account linking for Framer partners
- // so redirect to the standard login page
- if (otherAccounts && otherAccounts.length > 0) {
- throw new Error("framer-account-linking-not-allowed");
- }
-
- return true;
- }
-
if (account?.provider === "google" || account?.provider === "github") {
const userExists = await prisma.user.findUnique({
where: { email: user.email },
@@ -430,6 +419,38 @@ export const authOptions: NextAuthOptions = {
}),
]);
}
+ // Login with Framer
+ } else if (account?.provider === "framer") {
+ const userFound = await prisma.user.findUnique({
+ where: {
+ email: user.email,
+ },
+ include: {
+ accounts: true,
+ },
+ });
+
+ // account doesn't exist, let the user sign in
+ if (!userFound) {
+ // TODO: Remove this once we open up partners.dub.co to everyone
+ await updateConfig({
+ key: "partnersPortal",
+ value: user.email,
+ });
+ return true;
+ }
+
+ const otherAccounts = userFound?.accounts.filter(
+ (account) => account.provider !== "framer",
+ );
+
+ // we don't allow account linking for Framer partners
+ // so redirect to the standard login page
+ if (otherAccounts && otherAccounts.length > 0) {
+ throw new Error("framer-account-linking-not-allowed");
+ }
+
+ return true;
}
return true;
},
diff --git a/apps/web/lib/middleware/partners.ts b/apps/web/lib/middleware/partners.ts
index e89940c905..c679757fd6 100644
--- a/apps/web/lib/middleware/partners.ts
+++ b/apps/web/lib/middleware/partners.ts
@@ -8,8 +8,9 @@ const AUTHENTICATED_PATHS = [
"/programs",
"/marketplace",
"/onboarding",
+ "/waitlist",
"/settings",
- "/accounts",
+ "/account",
];
export default async function PartnersMiddleware(req: NextRequest) {
@@ -32,21 +33,23 @@ export default async function PartnersMiddleware(req: NextRequest) {
const partnersEnabled = await userIsInBeta(user.email, "partnersPortal");
if (!partnersEnabled) {
- return NextResponse.rewrite(new URL("/partners.dub.co", req.url));
- }
-
- const defaultPartner = await getDefaultPartner(user);
-
- if (!defaultPartner && !path.startsWith("/onboarding")) {
- return NextResponse.redirect(new URL("/onboarding", req.url));
- } else if (path === "/" || path.startsWith("/pn_")) {
- return NextResponse.redirect(new URL("/programs", req.url));
- } else if (
- ["/login", "/register"].some(
- (p) => path.startsWith(p) || path.endsWith(p),
- )
- ) {
- return NextResponse.redirect(new URL("/", req.url)); // Redirect authenticated users to dashboard
+ if (path !== "/waitlist") {
+ return NextResponse.redirect(new URL("/waitlist", req.url));
+ }
+ } else {
+ const defaultPartner = await getDefaultPartner(user);
+
+ if (!defaultPartner && !path.startsWith("/onboarding")) {
+ return NextResponse.redirect(new URL("/onboarding", req.url));
+ } else if (path === "/" || path.startsWith("/pn_")) {
+ return NextResponse.redirect(new URL("/programs", req.url));
+ } else if (
+ ["/login", "/register"].some(
+ (p) => path.startsWith(p) || path.endsWith(p),
+ )
+ ) {
+ return NextResponse.redirect(new URL("/", req.url)); // Redirect authenticated users to dashboard
+ }
}
}
diff --git a/apps/web/ui/auth/login/login-form.tsx b/apps/web/ui/auth/login/login-form.tsx
index 8cf5a986e7..e8e4119157 100644
--- a/apps/web/ui/auth/login/login-form.tsx
+++ b/apps/web/ui/auth/login/login-form.tsx
@@ -35,7 +35,7 @@ export const errorCodes = {
"too-many-login-attempts": "Too many login attempts. Please try again later.",
"email-not-verified": "Please verify your email address.",
"framer-account-linking-not-allowed":
- "It looks like you already have an account with us. Please sign in with the email you used to sign up.",
+ "It looks like you already have an account with us. Please sign in with your Framer account email instead.",
Callback:
"We encountered an issue processing your request. Please try again or contact support if the problem persists.",
OAuthSignin: