The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
connect user to project when saml login
Steven Tey4ed6f40650c9
diff --git a/pages/api/auth/[...nextauth].tsx b/pages/api/auth/[...nextauth].tsxindex 85fff2b8d9..a123c0ba10 100644--- a/pages/api/auth/[...nextauth].tsx+++ b/pages/api/auth/[...nextauth].tsx@@ -5,7 +5,7 @@ import { PrismaAdapter } from "@next-auth/prisma-adapter";import { sendEmail } from "emails";import LoginLink from "emails/login-link";import WelcomeEmail from "emails/welcome-email";-import NextAuth, { type NextAuthOptions } from "next-auth";+import NextAuth, { Profile, type NextAuthOptions } from "next-auth";import prisma from "#/lib/prisma";import jackson from "#/lib/jackson";import { isBlacklistedEmail } from "#/lib/edge-config";@@ -167,6 +167,37 @@ export const authOptions: NextAuthOptions = {},});}+ } else if (+ account?.provider === "saml" ||+ account?.provider === "saml-idp"+ ) {+ const samlProfile = profile as Profile & {+ requested?: { tenant?: string };+ };+ console.log("SAML SIGN IN", samlProfile);+ if (!samlProfile?.requested?.tenant) {+ return false;+ }+ const project = await prisma.project.findUnique({+ where: {+ id: samlProfile.requested.tenant,+ },+ });+ if (project) {+ await prisma.projectUsers.upsert({+ where: {+ userId_projectId: {+ projectId: project.id,+ userId: user.id,+ },+ },+ update: {},+ create: {+ projectId: project.id,+ userId: user.id,+ },+ });+ }}return true;},