Skip to content

Commit

Permalink
improvement: refactor saml/oidc
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-ray-wilson committed Oct 31, 2024
1 parent f8da2ef commit 1502bc5
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions frontend/src/views/Login/components/InitialStep/InitialStep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,22 +59,14 @@ export const InitialStep = ({ setStep, email, setEmail, password, setPassword }:
router.push(redirectUrl);
};

const handleSaml = (step: number) => {
const defaultOrgSlug = config.defaultAuthOrgSlug || serverDetails?.samlDefaultOrgSlug;
if (defaultOrgSlug) {
redirectToSaml(defaultOrgSlug);
} else {
setStep(step);
}
const handleSaml = (slug?: string | null) => {
if (slug) redirectToSaml(slug);
else setStep(2);
};

const handleOidc = (step: number) => {
const defaultOrgSlug = config.defaultAuthOrgSlug || serverDetails?.oidcDefaultOrgSlug;
if (defaultOrgSlug) {
redirectToOidc(defaultOrgSlug);
} else {
setStep(step);
}
const handleOidc = (slug?: string | null) => {
if (slug) redirectToOidc(slug);
else setStep(3);
};

const shouldDisplayLoginMethod = (method: LoginMethod) =>
Expand Down Expand Up @@ -172,8 +164,8 @@ export const InitialStep = ({ setStep, email, setEmail, password, setPassword }:
colorSchema="primary"
variant="outline_bg"
onClick={() => {
if (isSaml) handleSaml(2);
else handleOidc(3);
if (isSaml) handleSaml(serverDetails?.samlDefaultOrgSlug);
else handleOidc(serverDetails?.oidcDefaultOrgSlug);
}}
leftIcon={<FontAwesomeIcon icon={faLock} className="mr-2" />}
className="mx-0 h-10 w-full"
Expand All @@ -200,7 +192,7 @@ export const InitialStep = ({ setStep, email, setEmail, password, setPassword }:
colorSchema="primary"
variant="outline_bg"
onClick={() => {
handleSaml(2);
handleSaml(config.defaultAuthOrgSlug);
}}
leftIcon={<FontAwesomeIcon icon={faLock} className="mr-2" />}
className="mx-0 h-10 w-full"
Expand All @@ -215,7 +207,7 @@ export const InitialStep = ({ setStep, email, setEmail, password, setPassword }:
colorSchema="primary"
variant="outline_bg"
onClick={() => {
handleOidc(3);
handleOidc(config.defaultAuthOrgSlug);
}}
leftIcon={<FontAwesomeIcon icon={faLock} className="mr-2" />}
className="mx-0 h-10 w-full"
Expand Down

0 comments on commit 1502bc5

Please sign in to comment.