Skip to content

Commit

Permalink
account for different env
Browse files Browse the repository at this point in the history
  • Loading branch information
steven-tey committed Aug 17, 2023
1 parent 2de38cc commit 8cc2102
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
14 changes: 10 additions & 4 deletions lib/jackson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ import type {
IDirectorySyncController,
} from "@boxyhq/saml-jackson";

export const samlPath = "/api/auth/saml/callback";
export const samlAudience = "https://saml.dub.co";

const opts: JacksonOption = {
externalUrl: process.env.NEXTAUTH_URL as string,
samlPath,
externalUrl:
process.env.NODE_ENV === "production"
? "https://api.dub.co"
: `${process.env.NEXTAUTH_URL}`,
samlPath:
process.env.NODE_ENV === "production"
? "/auth/saml/callback"
: "/api/auth/saml/callback",
samlAudience,
db: {
engine: "planetscale",
Expand All @@ -23,7 +28,8 @@ const opts: JacksonOption = {
},
},
idpEnabled: true, // to allow folks to SSO directly from their IDP
scimPath: "/api/scim/v2.0", // custom SCIM endpoint
scimPath:
process.env.NODE_ENV === "production" ? "/scim/v2.0" : "/api/scim/v2.0", // custom SCIM endpoint
clientSecretVerifier: process.env.NEXTAUTH_SECRET as string,
};

Expand Down
1 change: 0 additions & 1 deletion pages/api/auth/[...nextauth].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ export const authOptions: NextAuthOptions = {
account?.provider === "saml" ||
account?.provider === "saml-idp"
) {
console.log({ user, account, profile });
let samlProfile;

if (account?.provider === "saml-idp") {
Expand Down
13 changes: 10 additions & 3 deletions pages/api/projects/[slug]/saml.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { withProjectAuth } from "#/lib/auth";
import jackson, { samlAudience, samlPath } from "#/lib/jackson";
import { APP_DOMAIN_WITH_NGROK } from "#/lib/constants";
import jackson, { samlAudience } from "#/lib/jackson";

export default withProjectAuth(
async (req, res, project) => {
Expand All @@ -15,7 +16,10 @@ export default withProjectAuth(
const response = {
connections,
issuer: samlAudience,
acs: `${process.env.NEXTAUTH_URL}${samlPath}`,
acs:
process.env.NODE_ENV === "production"
? "https://api.dub.co/auth/saml/callback"
: `${APP_DOMAIN_WITH_NGROK}/api/auth/saml/callback`,
};

return res.status(200).json(response);
Expand All @@ -30,7 +34,10 @@ export default withProjectAuth(
encodedRawMetadata: "",
metadataUrl,
defaultRedirectUrl: `${process.env.NEXTAUTH_URL}/auth/saml`,
redirectUrl: process.env.NEXTAUTH_URL as string,
redirectUrl:
process.env.NODE_ENV === "production"
? "https://api.dub.co"
: `${process.env.NEXTAUTH_URL}`,
tenant: project.id,
product: "Dub",
});
Expand Down

0 comments on commit 8cc2102

Please sign in to comment.