Fix connection testing for realm e-mail (#1303)
This commit is contained in:
parent
10d7c35b81
commit
f273ae70db
1 changed files with 24 additions and 3 deletions
|
@ -60,7 +60,7 @@ export const RealmSettingsEmailTab = ({
|
||||||
const authenticationEnabled = useWatch({
|
const authenticationEnabled = useWatch({
|
||||||
control,
|
control,
|
||||||
name: "smtpServer.authentication",
|
name: "smtpServer.authentication",
|
||||||
defaultValue: {},
|
defaultValue: "",
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleModalToggle = () => {
|
const handleModalToggle = () => {
|
||||||
|
@ -104,10 +104,31 @@ export const RealmSettingsEmailTab = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const testConnection = async () => {
|
const testConnection = async () => {
|
||||||
|
const serverSettings = { ...getValues()["smtpServer"] };
|
||||||
|
|
||||||
|
// Code below uses defensive coding as the server configuration uses an ambiguous record type.
|
||||||
|
if (typeof serverSettings.port === "string") {
|
||||||
|
serverSettings.port = Number(serverSettings.port);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof serverSettings.ssl === "string") {
|
||||||
|
serverSettings.ssl = serverSettings.ssl === true.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof serverSettings.starttls === "string") {
|
||||||
|
serverSettings.starttls = serverSettings.starttls === true.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
// For some reason the API wants a duplicate field for the authentication status.
|
||||||
|
// Somebody thought this was a good idea, so here we are.
|
||||||
|
if (serverSettings.authentication === true.toString()) {
|
||||||
|
serverSettings.auth = true;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await adminClient.realms.testSMTPConnection(
|
await adminClient.realms.testSMTPConnection(
|
||||||
{ realm: realm.realm! },
|
{ realm: realm.realm! },
|
||||||
getValues()["smtpServer"] || {}
|
serverSettings
|
||||||
);
|
);
|
||||||
addAlert(t("testConnectionSuccess"), AlertVariant.success);
|
addAlert(t("testConnectionSuccess"), AlertVariant.success);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -311,7 +332,7 @@ export const RealmSettingsEmailTab = ({
|
||||||
<Controller
|
<Controller
|
||||||
name="smtpServer.authentication"
|
name="smtpServer.authentication"
|
||||||
control={control}
|
control={control}
|
||||||
defaultValue={{}}
|
defaultValue=""
|
||||||
render={({ onChange, value }) => (
|
render={({ onChange, value }) => (
|
||||||
<Switch
|
<Switch
|
||||||
id="kc-authentication-switch"
|
id="kc-authentication-switch"
|
||||||
|
|
Loading…
Reference in a new issue