mirror of
https://github.com/awatertrevi/infisical.git
synced 2026-10-03 21:26:04 +00:00
Update support multiple domain and error handling
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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}` };
|
||||
|
||||
@@ -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"
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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 : "";
|
||||
try {
|
||||
config.allowSignUp = signUpMode !== "disabled";
|
||||
config.inviteOnlySignUp = signUpMode === "invite-only";
|
||||
config.allowSpecificDomainSignUp = signUpMode === "anyone" ? allowSpecificDomain : "";
|
||||
|
||||
await updateServerConfig(config);
|
||||
await updateServerConfig(config);
|
||||
|
||||
createNotification({
|
||||
text: "Successfully changed sign up mode.",
|
||||
type: "success"
|
||||
});
|
||||
}
|
||||
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)}
|
||||
|
||||
Reference in New Issue
Block a user