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.

added samlConfigured prop

Steven Teycb3c0f28ed18
diff --git a/app/ui/modal-provider.tsx b/app/ui/modal-provider.tsx
index 3f30012a19..69d5b27080 100644
--- a/app/ui/modal-provider.tsx
+++ b/app/ui/modal-provider.tsx
@@ -64,7 +64,7 @@ export default function ModalProvider({ children }: { children: ReactNode }) {
const { setShowImportBitlyModal, ImportBitlyModal } = useImportBitlyModal();
const { setShowImportShortModal, ImportShortModal } = useImportShortModal();
- const { error, loading } = useProject();
+ const { samlConfigured, error, loading } = useProject();
const { data: session } = useSession();
const router = useRouter();
diff --git a/lib/types.ts b/lib/types.ts
index 47199127c7..28bf272e87 100644
--- a/lib/types.ts
+++ b/lib/types.ts
@@ -56,6 +56,7 @@ export interface ProjectProps {
usage: number;
usageLimit: number;
plan: PlanProps;
+ samlConfigured: boolean;
stripeId?: string;
billingCycleStart?: number;
createdAt?: Date;
diff --git a/pages/api/auth/[...nextauth].tsx b/pages/api/auth/[...nextauth].tsx
index f2a25dc58a..a6c46e8bdb 100644
--- a/pages/api/auth/[...nextauth].tsx
+++ b/pages/api/auth/[...nextauth].tsx
@@ -171,7 +171,6 @@ export const authOptions: NextAuthOptions = {
const samlProfile = profile as Profile & {
requested?: { tenant?: string };
};
- console.log("SAML SIGN IN", samlProfile);
if (!samlProfile?.requested?.tenant) {
return false;
}
@@ -196,11 +195,13 @@ export const authOptions: NextAuthOptions = {
});
}
} else if (account?.provider === "saml-idp") {
+ // you don't get SAML tenant for some reason
+
console.log({ user, account, profile });
}
return true;
},
- jwt: async ({ token, user, trigger }) => {
+ jwt: async ({ token, account, user, trigger }) => {
// force log out banned users
if (!token.email || (await isBlacklistedEmail(token.email))) {
return {};
@@ -220,6 +221,7 @@ export const authOptions: NextAuthOptions = {
token.email = refreshedUser?.email;
token.image = refreshedUser?.image;
}
+
return token;
},
session: async ({ session, token }) => {
diff --git a/pages/api/auth/saml/authorize.ts b/pages/api/auth/saml/authorize.ts
index afff735580..a12cca729a 100644
--- a/pages/api/auth/saml/authorize.ts
+++ b/pages/api/auth/saml/authorize.ts
@@ -1,5 +1,5 @@
-import jackson from "#/lib/jackson";
import { NextApiRequest, NextApiResponse } from "next";
+import jackson from "#/lib/jackson";
export default async function handler(
req: NextApiRequest,
diff --git a/pages/api/projects/[slug]/saml.ts b/pages/api/projects/[slug]/saml.ts
index 22066fac30..8c8a51818b 100644
--- a/pages/api/projects/[slug]/saml.ts
+++ b/pages/api/projects/[slug]/saml.ts
@@ -1,5 +1,6 @@
import { withProjectAuth } from "#/lib/auth";
import jackson from "#/lib/jackson";
+import prisma from "#/lib/prisma";
export default withProjectAuth(
async (req, res, project) => {
@@ -35,6 +36,15 @@ export default withProjectAuth(
product: "Dub",
});
+ await prisma.project.update({
+ where: {
+ id: project.id,
+ },
+ data: {
+ samlConfigured: true,
+ },
+ });
+
return res.status(200).json(data);
// DELETE /api/projects/[slug]/saml – delete all SAML connections
@@ -51,6 +61,15 @@ export default withProjectAuth(
clientSecret,
});
+ await prisma.project.update({
+ where: {
+ id: project.id,
+ },
+ data: {
+ samlConfigured: false,
+ },
+ });
+
return res.status(200).json(response);
} else {
res.setHeader("Allow", ["GET", "POST", "DELETE"]);
diff --git a/prisma/schema.prisma b/prisma/schema.prisma
index d2e673dddb..f339ce6cbd 100644
--- a/prisma/schema.prisma
+++ b/prisma/schema.prisma
@@ -75,6 +75,7 @@ model Project {
usage Int @default(0)
usageLimit Int @default(1000)
plan String @default("free")
+ samlConfigured Boolean @default(false)
stripeId String? @unique // Stripe subscription ID
billingCycleStart Int? // day of the month when the billing cycle starts