The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Add Framer OAuth support and update login redirection
Kiran Kc075ec9e0f95
diff --git a/apps/web/lib/auth/options.ts b/apps/web/lib/auth/options.tsindex c3e1b4bcb7..964ce21052 100644--- a/apps/web/lib/auth/options.ts+++ b/apps/web/lib/auth/options.ts@@ -259,6 +259,27 @@ export const authOptions: NextAuthOptions = {};},}),++ // Framer+ {+ id: "framer",+ name: "Framer",+ type: "oauth",+ clientId: process.env.FRAMER_CLIENT_ID,+ clientSecret: process.env.FRAMER_CLIENT_SECRET,+ checks: ["state"],+ authorization: "https://api.development.framer.com/auth/oauth/authorize",+ token: "https://api.development.framer.com/auth/oauth/token",+ userinfo: "https://api.development.framer.com/auth/oauth/profile",+ profile({ sub, email, name, picture }) {+ return {+ id: sub,+ name,+ email,+ image: picture,+ };+ },+ },],// @ts-ignoreadapter: PrismaAdapter(prisma),@@ -285,6 +306,7 @@ export const authOptions: NextAuthOptions = {callbacks: {signIn: async ({ user, account, profile }) => {console.log({ user, account, profile });+if (!user.email || (await isBlacklistedEmail(user.email))) {return false;}@@ -293,6 +315,35 @@ 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 },diff --git a/apps/web/lib/middleware/partners.ts b/apps/web/lib/middleware/partners.tsindex 816fe8b2fe..28177978d1 100644--- a/apps/web/lib/middleware/partners.ts+++ b/apps/web/lib/middleware/partners.ts@@ -43,7 +43,9 @@ export default async function PartnersMiddleware(req: NextRequest) {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))) {+ } else if (+ ["/login", "/register", "/framer/login"].some((p) => path.startsWith(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.tsxindex b517b53532..8cf5a986e7 100644--- a/apps/web/ui/auth/login/login-form.tsx+++ b/apps/web/ui/auth/login/login-form.tsx@@ -34,6 +34,8 @@ export const errorCodes = {"Account has been locked due to too many login attempts. Please contact support to unlock your account.","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.",Callback:"We encountered an issue processing your request. Please try again or contact support if the problem persists.",OAuthSignin: