Skip to content

Pre-check SSO by domain

Validate that a user's email domain has an active SSO connection before redirecting to prevent dead-end redirects and improve user experience.

When using discovery through loginHint, validate that the user’s email domain has an active SSO connection before redirecting. This prevents dead-end redirects and improves user experience by routing users to the correct authentication path.

Use domain pre-checking when:

  • You implement identifier-driven or SSO button flows that collect email first
  • You infer SSO availability from the user’s email domain
  • You want to show helpful error messages for domains without SSO

Skip this check when:

  • You already pass organizationId explicitly (you know the organization)
  • You implement organization-specific pages where SSO is always available
  1. Capture the user’s email and extract the domain

    Section titled “Capture the user’s email and extract the domain”

    First, collect the user’s email address through your login form.

    Login form handler
    // Extract domain from user's email
    const email = req.body.email;
    const domain = email.split('@')[1]; // e.g., "acmecorp.com"
  2. Use the Scalekit API to check if the domain has an active SSO connection configured.

    Express.js
    // Use case: Check if user's domain has SSO before redirecting
    app.post('/auth/check-sso', async (req, res) => {
    const { email } = req.body;
    const domain = email.split('@')[1];
    try {
    // Query Scalekit for connections matching this domain
    const connections = await scalekit.connection.listConnections({
    domain: domain
    });
    if (connections.length > 0) {
    // Domain has active SSO - redirect to SSO login
    const authorizationURL = scalekit.getAuthorizationUrl(
    process.env.REDIRECT_URI,
    { loginHint: email }
    );
    res.json({ ssoAvailable: true, redirectUrl: authorizationURL });
    } else {
    // No SSO configured - route to password or social login
    res.json({ ssoAvailable: false, message: 'Please use password login' });
    }
    } catch (error) {
    console.error('Failed to check SSO availability:', error);
    res.status(500).json({ error: 'sso_check_failed' });
    }
    });
  3. Based on the API response, either redirect to SSO or show alternative authentication options.

    Client-side routing
    // Handle the response from your backend
    const response = await fetch('/auth/check-sso', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ email: userEmail })
    });
    const data = await response.json();
    if (data.ssoAvailable) {
    // Redirect to SSO login
    window.location.href = data.redirectUrl;
    } else {
    // Show password login or social authentication options
    showPasswordLoginForm();
    }