Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

Update support multiple domain and error handling

Salman2ef8781378cc
diff --git a/backend/src/ee/routes/v1/saml-router.ts b/backend/src/ee/routes/v1/saml-router.ts
index 4c0e43cd6a..f81c21ffd4 100644
--- a/backend/src/ee/routes/v1/saml-router.ts
+++ b/backend/src/ee/routes/v1/saml-router.ts
@@ -105,7 +105,7 @@ export const registerSamlRouter = async (server: FastifyZodProvider) => {
email,
firstName: profile.firstName as string,
lastName: profile.lastName as string,
- isSignupAllowed: Boolean(serverCfg.allowSignUp && serverCfg.inviteOnlySignUp),
+ isSignupAllowed: Boolean(serverCfg.allowSignUp),
relayState: (req.body as { RelayState?: string }).RelayState,
authProvider: (req as unknown as FastifyRequest).ssoConfig?.authProvider as string,
orgId: (req as unknown as FastifyRequest).ssoConfig?.orgId as string
diff --git a/backend/src/server/routes/v3/signup-router.ts b/backend/src/server/routes/v3/signup-router.ts
index 257a4c1733..e0ce210065 100644
--- a/backend/src/server/routes/v3/signup-router.ts
+++ b/backend/src/server/routes/v3/signup-router.ts
@@ -4,6 +4,7 @@ import { UsersSchema } from "@app/db/schemas";
import { getConfig } from "@app/lib/config/env";
import { BadRequestError } from "@app/lib/errors";
import { authRateLimit } from "@app/server/config/rateLimiter";
+import { getServerCfg } from "@app/services/super-admin/super-admin-service";
import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
export const registerSignupRouter = async (server: FastifyZodProvider) => {
@@ -25,15 +26,16 @@ export const registerSignupRouter = async (server: FastifyZodProvider) => {
},
handler: async (req) => {
const { email } = req.body;
- const config = await server.services.superAdmin.initServerCfg();
+ const serverCfg = await getServerCfg();
- if (config?.allowSpecificDomainSignUp) {
+ if (serverCfg?.allowSpecificDomainSignUp) {
const domain = email.split("@")[1];
-
- if (domain !== config.allowSpecificDomainSignUp)
+ const allowedDomains = serverCfg.allowSpecificDomainSignUp.split(",").map((e) => e.trim());
+ if (!allowedDomains.includes(domain)) {
throw new BadRequestError({
- message: `User email domain (@${domain}) is not supported`
+ message: `Email with a domain (@${domain}) is not supported`
});
+ }
}
await server.services.signup.beginEmailSignupProcess(email);
return { message: `Sent an email verification code to ${email}` };
diff --git a/backend/src/services/auth/auth-login-service.ts b/backend/src/services/auth/auth-login-service.ts
index 569b3d374c..f43fe063cc 100644
--- a/backend/src/services/auth/auth-login-service.ts
+++ b/backend/src/services/auth/auth-login-service.ts
@@ -275,10 +275,10 @@ export const authLoginServiceFactory = ({ userDAL, tokenService, smtpService }:
if (serverCfg?.allowSpecificDomainSignUp) {
const domain = email.split("@")[1];
-
- if (domain !== serverCfg.allowSpecificDomainSignUp)
+ const allowedDomains = serverCfg.allowSpecificDomainSignUp.split(",").map((e) => e.trim());
+ if (!allowedDomains.includes(domain))
throw new BadRequestError({
- message: `User email domain (@${domain}) is not supported`,
+ message: `Email with a domain (@${domain}) is not supported`,
name: "Oauth 2 login"
});
}
diff --git a/frontend/src/components/signup/EnterEmailStep.tsx b/frontend/src/components/signup/EnterEmailStep.tsx
index e317a4ea5b..058c231064 100644
--- a/frontend/src/components/signup/EnterEmailStep.tsx
+++ b/frontend/src/components/signup/EnterEmailStep.tsx
@@ -1,7 +1,9 @@
import React, { useState } from "react";
import { useTranslation } from "react-i18next";
import Link from "next/link";
+import axios from "axios";
+import { useNotificationContext } from "@app/components/context/Notifications/NotificationProvider";
import { useSendVerificationEmail } from "@app/hooks/api";
import { Button, Input } from "../v2";
@@ -25,6 +27,7 @@ export default function EnterEmailStep({
setEmail,
incrementStep
}: DownloadBackupPDFStepProps): JSX.Element {
+ const { createNotification } = useNotificationContext();
const { mutateAsync } = useSendVerificationEmail();
const [emailError, setEmailError] = useState(false);
const { t } = useTranslation();
@@ -46,8 +49,18 @@ export default function EnterEmailStep({
// If everything is correct, go to the next step
if (!emailCheckBool) {
- await mutateAsync({ email });
- incrementStep();
+ try {
+ await mutateAsync({ email });
+ incrementStep();
+ } catch(e) {
+ if (axios.isAxiosError(e)) {
+ const { message = "Something went wrong" } = e.response?.data as { message: string};
+ createNotification({
+ type: "error",
+ text: message
+ })
+ }
+ }
}
};
diff --git a/frontend/src/views/admin/DashboardPage/DashboardPage.tsx b/frontend/src/views/admin/DashboardPage/DashboardPage.tsx
index 181dc890ad..340c1662a5 100644
--- a/frontend/src/views/admin/DashboardPage/DashboardPage.tsx
+++ b/frontend/src/views/admin/DashboardPage/DashboardPage.tsx
@@ -66,17 +66,25 @@ export const AdminDashboardPage = () => {
}, [config]);
const handleSubmit = async () => {
- config.allowSignUp = signUpMode !== "disabled";
- config.inviteOnlySignUp = signUpMode === "invite-only";
- config.allowSpecificDomainSignUp = signUpMode === "anyone" ? allowSpecificDomain : "";
-
- await updateServerConfig(config);
-
- createNotification({
- text: "Successfully changed sign up mode.",
- type: "success"
- });
- }
+ try {
+ config.allowSignUp = signUpMode !== "disabled";
+ config.inviteOnlySignUp = signUpMode === "invite-only";
+ config.allowSpecificDomainSignUp = signUpMode === "anyone" ? allowSpecificDomain : "";
+
+ await updateServerConfig(config);
+
+ createNotification({
+ text: "Successfully changed sign up setting.",
+ type: "success"
+ });
+ } catch (e) {
+ console.error(e);
+ createNotification({
+ type: "error",
+ text: "Failed to update sign up setting."
+ });
+ }
+ };
return (
<div className="container mx-auto max-w-7xl px-4 pb-12 text-white dark:[color-scheme:dark]">
@@ -118,12 +126,12 @@ export const AdminDashboardPage = () => {
{signUpMode === "anyone" && (
<div className="mt-4 flex items-center justify-between">
<div className="mb-4 flex text-mineshaft-100">
- Allow email with only specific domain
+ Allow email with only specific domain(s)
</div>
<FormControl label="Leave blank to allow any domain handle" className="w-72">
<div>
<Input
- placeholder="domain.com"
+ placeholder="domain.com, domain2.com"
leftIcon={<FontAwesomeIcon icon={faAt} />}
value={allowSpecificDomain}
onChange={(ev) => setAllowSpecificDomain(ev.target.value)}