Transparently fall back to SAML when a domain enforces SSO, with the Prelude JavaScript SDK.
When a SAML connection has enforce login enabled, users whose email domain is covered by the connection must authenticate through SSO. Other login methods are refused — and the Web SDK gives you a typed signal so you can route those users into SAML without showing them an error.
If your app starts an OTP login for an enforced email, the server responds with 403 saml_login_required. startOTP routes failures through the SDK’s error mapper, so it throws a typed SAMLLoginRequiredError, exported as PrldErrors.SAMLLoginRequired:
import { PrldErrors } from "@prelude.so/js-sdk";try { await client.startOTP({ identifier: { type: "email_address", value: email }, }); // OTP sent — show your code-entry screen.} catch (err) { if (err instanceof PrldErrors.SAMLLoginRequired) { // This domain enforces SSO — restart via SAML instead. } else { // Handle other errors (rate limiting, invalid identifier, …). }}
On SAMLLoginRequiredError, restart the flow with loginWithSAMLByEmail. It resolves the connection from the same email domain and redirects the user to the Identity Provider:
import { PrldErrors } from "@prelude.so/js-sdk";async function startEmailLogin(email) { try { await client.startOTP({ identifier: { type: "email_address", value: email }, }); // OTP path: show the code-entry screen. } catch (err) { if (err instanceof PrldErrors.SAMLLoginRequired) { // Enforced domain — hand off to SSO. This navigates to the IdP. await client.loginWithSAMLByEmail({ email, redirectURI: window.location.origin + window.location.pathname, }); return; } throw err; }}
The user authenticates with the IdP and is redirected back with a challenge_token, which you finalize exactly as in the SAML Login guide.
The fallback is transparent: the user enters their email expecting an OTP and
is seamlessly redirected to their company’s SSO instead. No separate “Sign in
with SSO” button is required.
Try it
This single email field starts an OTP login and silently upgrades to SAML when the domain enforces SSO.