From 2b35a4c8e2a9d2e734177b8b105330ce5c7d5195 Mon Sep 17 00:00:00 2001 From: Cyrus Goh Date: Wed, 13 Nov 2024 10:50:46 -0800 Subject: [PATCH] rework sso, sso directly with email --- web-auth/src/components/Auth.svelte | 28 +++++------ web-auth/src/components/SSOForm.svelte | 70 -------------------------- 2 files changed, 12 insertions(+), 86 deletions(-) delete mode 100644 web-auth/src/components/SSOForm.svelte diff --git a/web-auth/src/components/Auth.svelte b/web-auth/src/components/Auth.svelte index dc4a3265d6b0..cef04da75082 100644 --- a/web-auth/src/components/Auth.svelte +++ b/web-auth/src/components/Auth.svelte @@ -9,7 +9,6 @@ import EmailPasswordForm from "./EmailPasswordForm.svelte"; import { getConnectionFromEmail } from "./utils"; import OrSeparator from "./OrSeparator.svelte"; - import SSOForm from "./SSOForm.svelte"; import EmailSubmissionForm from "./EmailSubmissionForm.svelte"; import Disclaimer from "./Disclaimer.svelte"; import Spacer from "./Spacer.svelte"; @@ -75,28 +74,30 @@ webAuth = new auth0.WebAuth(authOptions); } + function authorizeSSO(email: string, connectionName: string) { + webAuth.authorize({ + connection: connectionName, + login_hint: email, + prompt: "login", + }); + } + function processEmailSubmission(event) { email = event.detail.email; const connectionName = getConnectionFromEmail(email, connectionMapObj); if (connectionName) { - step = AuthStep.SSO; + authorizeSSO(email, connectionName); } else { step = AuthStep.Login; } } function getHeadingText(step: AuthStep): string { - if (isLegacy) { - return "Log in"; - } - switch (step) { case AuthStep.Base: return "Log in or sign up"; - case AuthStep.SSO: - return "Log in with SSO"; case AuthStep.Login: return "Log in with email"; case AuthStep.SignUp: @@ -107,19 +108,15 @@ return ""; } } - $: headingText = getHeadingText(step); function getSubheadingText(step: AuthStep, email: string): string { switch (step) { - case AuthStep.SSO: - return `SAML SSO enabled workspace is associated with ${email}`; case AuthStep.Login: return `Log in using ${email}`; default: return ""; } } - $: subheadingText = getSubheadingText(step, email); function backToBaseStep() { step = AuthStep.Base; @@ -128,6 +125,9 @@ onMount(() => { initConfig(); }); + + $: headingText = getHeadingText(step); + $: subheadingText = getSubheadingText(step, email); @@ -169,10 +169,6 @@ {/if} - {#if step === AuthStep.SSO} - - {/if} - {#if step === AuthStep.Login || step === AuthStep.SignUp} - import { createEventDispatcher } from "svelte"; - import CtaButton from "@rilldata/web-common/components/calls-to-action/CTAButton.svelte"; - import { getConnectionFromEmail } from "./utils"; - import { ArrowLeftIcon } from "lucide-svelte"; - import { WebAuth } from "auth0-js"; - - const dispatch = createEventDispatcher(); - - export let disabled = false; - export let email = ""; - export let webAuth: WebAuth; - export let connectionMapObj: Record; - - let errorText = ""; - - function handleClick() { - void authorizeSSO(email.toLowerCase()); - } - - function displayError(err: any) { - errorText = err.message; - } - - function authorizeSSO(email: string) { - disabled = true; - errorText = ""; - - const connectionName = getConnectionFromEmail(email, connectionMapObj); - - if (!connectionName) { - displayError({ - message: `IDP for the email ${email} not found. Please contact your administrator.`, - }); - disabled = false; - return; - } - - webAuth.authorize({ - connection: connectionName, - login_hint: email, - prompt: "login", - }); - } - - -
- -
- Continue with SAML SSO -
-
- { - dispatch("back"); - }} - > -
- - Back -
-
-
- -{#if errorText} -
{errorText}
-{/if}