sso.ts 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import getMeta from '../../../utils/meta'
  2. import { DomainInfo } from '../components/emails/add-email/input'
  3. import { ExposedSettings } from '../../../../../types/exposed-settings'
  4. import { Institution } from '../../../../../types/institution'
  5. export const ssoAvailableForDomain = (
  6. domain: DomainInfo | null
  7. ): domain is DomainInfo => {
  8. const { hasSamlBeta, hasSamlFeature } = getMeta(
  9. 'ol-ExposedSettings'
  10. ) as ExposedSettings
  11. if (!hasSamlFeature || !domain || !domain.confirmed || !domain.university) {
  12. return false
  13. }
  14. if (domain.university.ssoEnabled) {
  15. return true
  16. }
  17. return Boolean(hasSamlBeta && domain.university.ssoBeta)
  18. }
  19. export const ssoAvailableForInstitution = (institution: Institution | null) => {
  20. const { hasSamlBeta, hasSamlFeature } = getMeta(
  21. 'ol-ExposedSettings'
  22. ) as ExposedSettings
  23. if (
  24. !hasSamlFeature ||
  25. !institution ||
  26. !institution.confirmed ||
  27. !institution.isUniversity
  28. ) {
  29. return false
  30. }
  31. if (institution.ssoEnabled) {
  32. return true
  33. }
  34. return hasSamlBeta && institution.ssoBeta
  35. }