diff --git a/package-lock.json b/package-lock.json index 90d950660eb..6cbbabc4784 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8803,7 +8803,9 @@ "license": "MIT" }, "node_modules/@types/auth0-js": { - "version": "9.21.5", + "version": "9.21.6", + "resolved": "https://registry.npmjs.org/@types/auth0-js/-/auth0-js-9.21.6.tgz", + "integrity": "sha512-wsvfk03WzQDXCbMdX8lQZH2Thh5AQk9SKQcxrBN1EdRkIOgkw9aIixxBpzsTHu/gj0I514BGQv7t5EyZSgVRmQ==", "dev": true, "license": "MIT" }, @@ -10788,7 +10790,9 @@ } }, "node_modules/auth0-js": { - "version": "9.24.1", + "version": "9.28.0", + "resolved": "https://registry.npmjs.org/auth0-js/-/auth0-js-9.28.0.tgz", + "integrity": "sha512-2xIfQIGM0vX3IdPR91ztLO2+Ar2I5+3iFKcjuZO+LV9vRh4Wje+Ka1hnHjMU9dH892Lm3ZxBAHxRo68YToUhfg==", "dev": true, "license": "MIT", "dependencies": { @@ -34873,8 +34877,8 @@ "version": "0.0.0", "devDependencies": { "@sveltejs/vite-plugin-svelte": "^3.1.2", - "@types/auth0-js": "^9.14.7", - "auth0-js": "^9.20.2", + "@types/auth0-js": "^9.21.6", + "auth0-js": "^9.28.0", "autoprefixer": "^10.4.20", "postcss": "^8.4.47", "svelte": "^4.2.19", diff --git a/web-auth/src/components/Auth.svelte b/web-auth/src/components/Auth.svelte index d76f0924408..b05a26e2120 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"; @@ -32,6 +31,7 @@ let webAuth: WebAuth; $: isLegacy = false; + $: isSignup = false; function isDomainDisabled(email: string): boolean { return disableForgotPassDomainsArr.some((domain) => @@ -42,82 +42,78 @@ $: domainDisabled = isDomainDisabled(email); function initConfig() { - const config = JSON.parse( - decodeURIComponent(escape(window.atob(configParams))), - ) as Config; - - const isSignup = config?.extraParams?.screen_hint === "signup"; - - if (isSignup) { - step = AuthStep.SignUp; - } - - if (cloudClientIDsArr.includes(config?.clientID)) { - isLegacy = true; - } - - const authOptions: AuthOptions = Object.assign( - { - overrides: { - __tenant: config.auth0Tenant, - __token_issuer: config.authorizationServer.issuer, + try { + if ( + import.meta.env.DEV && + (!configParams || configParams === "undefined") + ) { + console.warn( + "No auth config provided. In development mode - auth flows will not work.", + ); + errorText = "Authentication is not configured in development mode"; + return; + } + + const config = JSON.parse( + decodeURIComponent(escape(window.atob(configParams))), + ) as Config; + + isSignup = config?.extraParams?.screen_hint === "signup"; + + if (cloudClientIDsArr.includes(config?.clientID)) { + isLegacy = true; + } + + const authOptions: AuthOptions = Object.assign( + { + overrides: { + __tenant: config.auth0Tenant, + __token_issuer: config.authorizationServer.issuer, + }, + domain: config.auth0Domain, + clientID: config.clientID, + redirectUri: config.callbackURL, + responseType: "code", }, - domain: config.auth0Domain, - clientID: config.clientID, - redirectUri: config.callbackURL, - responseType: "code", - }, - config.internalOptions, - ); + config.internalOptions, + ); - webAuth = new auth0.WebAuth(authOptions); + webAuth = new auth0.WebAuth(authOptions); + } catch (e) { + console.error("Failed to initialize auth:", e); + errorText = "Failed to initialize authentication in development mode"; + } } - function processEmailSubmission(event) { + function processEmailSubmission(event: any) { email = event.detail.email; - const connectionName = getConnectionFromEmail(email, connectionMapObj); - - if (connectionName) { - step = AuthStep.SSO; - } else { - step = AuthStep.Login; - } + step = AuthStep.SignUp; } 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: - return "Sign up with email"; + return `Log in or sign up with ${email}`; case AuthStep.Thanks: return "Thanks for signing up!"; default: 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; @@ -126,6 +122,9 @@ onMount(() => { initConfig(); }); + + $: headingText = getHeadingText(step); + $: subheadingText = getSubheadingText(step, email); @@ -133,7 +132,7 @@
- {headingText} + {@html headingText}
{#if subheadingText}
@@ -164,19 +163,17 @@ - - {/if} - - {#if step === AuthStep.SSO} - + {/if} {#if step === AuthStep.Login || step === AuthStep.SignUp} { - if (signupErr) { - handleAuthError(signupErr); + (loginErr) => { + if (loginErr) { + displayError({ message: loginErr?.description }); + showForgetPassword = true; } else { disabled = false; } }, ); } else { - webAuth.login( + console.log("attempt to sign up and login"); + // Attempt to sign up and login the user + webAuth.redirect.signupAndLogin( { - realm: DATABASE_CONNECTION, - username: email, + connection: DATABASE_CONNECTION, + email: email, password: password, }, (err) => { if (err) { - displayError({ message: err?.description }); + console.log("err", err); + // Check if the error is about user already existing + if (err.description && err.description.includes("User exists.")) { + // If user exists, try logging them in + console.log("user exists, trying to login"); + webAuth.login( + { + realm: DATABASE_CONNECTION, + username: email, + password: password, + }, + (loginErr) => { + if (loginErr) { + displayError({ message: loginErr?.description }); + showForgetPassword = true; + } else { + disabled = false; + } + }, + ); + } else { + handleAuthError(err); + showForgetPassword = true; + } } else { disabled = false; } @@ -131,6 +155,7 @@ } } catch (err) { handleAuthError(err); + showForgetPassword = true; } } diff --git a/web-auth/src/components/EmailSubmissionForm.svelte b/web-auth/src/components/EmailSubmissionForm.svelte index 9b2f2608bfe..abab37040c5 100644 --- a/web-auth/src/components/EmailSubmissionForm.svelte +++ b/web-auth/src/components/EmailSubmissionForm.svelte @@ -1,9 +1,13 @@ - -
- -
- Continue with SAML SSO -
-
- { - dispatch("back"); - }} - > -
- - Back -
-
-
- -{#if errorText} -
{errorText}
-{/if} diff --git a/web-common/src/components/calls-to-action/CTANeedHelp.svelte b/web-common/src/components/calls-to-action/CTANeedHelp.svelte index 91574c9e6b7..5ae505b6ae4 100644 --- a/web-common/src/components/calls-to-action/CTANeedHelp.svelte +++ b/web-common/src/components/calls-to-action/CTANeedHelp.svelte @@ -1,5 +1,5 @@

- Need help? Reach out to us on Discordsupport@rilldata.com