:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
import { useValues } from 'kea'
import { LemonSelect, LemonSelectOptions } from '@posthog/lemon-ui'
import { SocialLoginIcon } from 'lib/components/SocialLoginButton/SocialLoginIcon'
import { SSO_PROVIDER_NAMES } from 'lib/constants'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { SSOProvider } from '~/types'
export interface SSOSelectInterface {
value: SSOProvider | ''
loading: boolean
onChange: (value: SSOProvider | '') => void
samlAvailable: boolean
oidcAvailable?: boolean
disabledReason?: string | null
}
export function SSOSelect({
value,
loading,
onChange,
samlAvailable,
oidcAvailable,
disabledReason,
}: SSOSelectInterface): JSX.Element | null {
const { preflight } = useValues(preflightLogic)
if (!preflight) {
return null
}
const authProviders = Object.keys(preflight.available_social_auth_providers) as SSOProvider[]
const options: LemonSelectOptions<SSOProvider | ''> = [{ value: '', label: "Don't enforce" }]
authProviders.forEach((key) => {
options.push({
value: key,
label: SSO_PROVIDER_NAMES[key],
disabledReason: preflight.available_social_auth_providers[key]
? undefined
: 'This provider is not configured.',
icon: <SocialLoginIcon provider={key} className="w-4 h-4" />,
})
})
options.push({
value: 'saml',
label: SSO_PROVIDER_NAMES['saml'],
disabledReason: !samlAvailable ? 'This provider is not configured.' : undefined,
icon: <SocialLoginIcon provider="saml" className="w-4 h-4" />,
})
if (oidcAvailable !== undefined) {
options.push({
value: 'oidc',
label: SSO_PROVIDER_NAMES.oidc,
disabledReason: oidcAvailable ? undefined : 'This provider is not configured.',
icon: <SocialLoginIcon provider="oidc" className="w-4 h-4" />,
})
}
return (
<LemonSelect
value={value}
options={options}
loading={loading}
disabledReason={loading ? 'Cannot change while loading' : disabledReason}
fullWidth
onChange={onChange}
/>
)
}