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.

Enhance SAML enforcement and workspace user logic

Kiran K02b3d560fe17
diff --git a/apps/web/lib/auth/options.ts b/apps/web/lib/auth/options.ts
index 44868aeb7a..f1d7c453ad 100644
--- a/apps/web/lib/auth/options.ts
+++ b/apps/web/lib/auth/options.ts
@@ -20,7 +20,7 @@ import GoogleProvider from "next-auth/providers/google";
import { headers } from "next/headers";
import { createId } from "../api/create-id";
import { qstash } from "../cron";
-import { isGenericEmail } from "../emails";
+import { isGenericEmail } from "../is-generic-email";
import { completeProgramApplications } from "../partners/complete-program-applications";
import { FRAMER_API_HOST } from "./constants";
import {
@@ -343,7 +343,7 @@ export const authOptions: NextAuthOptions = {
return false;
}
- // SSO enforcement check
+ // If the user is not using SAML, we need to check if SAML is enforced for the email domain
if (
account?.provider !== "saml" &&
account?.provider !== "saml-idp" &&
@@ -409,19 +409,40 @@ export const authOptions: NextAuthOptions = {
if (!samlProfile?.requested?.tenant) {
return false;
}
+
const workspace = await prisma.project.findUnique({
where: {
id: samlProfile.requested.tenant,
},
+ select: {
+ id: true,
+ ssoEmailDomain: true,
+ },
});
+
if (workspace) {
+ const { ssoEmailDomain } = workspace;
+
+ if (!ssoEmailDomain) {
+ return false;
+ }
+
+ const emailDomain = user.email.split("@")[1];
+
+ if (
+ emailDomain.toLocaleLowerCase() !==
+ ssoEmailDomain.toLocaleLowerCase()
+ ) {
+ return false;
+ }
+
await Promise.allSettled([
// add user to workspace
prisma.projectUsers.upsert({
where: {
userId_projectId: {
- projectId: workspace.id,
userId: user.id,
+ projectId: workspace.id,
},
},
update: {},