index.tsx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. import { useParams } from 'common'
  2. import { ExternalLink } from 'lucide-react'
  3. import Link from 'next/link'
  4. import { Alert, AlertDescription, AlertTitle, Button, WarningIcon } from 'ui'
  5. import {
  6. PageSection,
  7. PageSectionContent,
  8. PageSectionDescription,
  9. PageSectionMeta,
  10. PageSectionSummary,
  11. PageSectionTitle,
  12. } from 'ui-patterns/PageSection'
  13. import { getPhoneProviderValidationSchema, PROVIDERS_SCHEMAS } from '../AuthProvidersFormValidation'
  14. import type { Provider } from './AuthProvidersForm.types'
  15. import { ProviderForm } from './ProviderForm'
  16. import AlertError from '@/components/ui/AlertError'
  17. import { ResourceList } from '@/components/ui/Resource/ResourceList'
  18. import { HorizontalShimmerWithIcon } from '@/components/ui/Shimmers'
  19. import { useAuthConfigQuery } from '@/data/auth/auth-config-query'
  20. export const AuthProvidersForm = () => {
  21. const { ref: projectRef } = useParams()
  22. const {
  23. data: authConfig,
  24. error: authConfigError,
  25. isPending: isLoading,
  26. isError,
  27. isSuccess,
  28. } = useAuthConfigQuery({ projectRef })
  29. return (
  30. <PageSection>
  31. <PageSectionMeta>
  32. <PageSectionSummary>
  33. <PageSectionTitle>Auth Providers</PageSectionTitle>
  34. <PageSectionDescription>
  35. Authenticate your users through a suite of providers and login methods
  36. </PageSectionDescription>
  37. </PageSectionSummary>
  38. </PageSectionMeta>
  39. <PageSectionContent>
  40. {isError ? (
  41. <AlertError
  42. error={authConfigError}
  43. subject="Failed to retrieve auth configuration for hooks"
  44. />
  45. ) : (
  46. <div className="-space-y-px">
  47. {authConfig?.EXTERNAL_EMAIL_ENABLED && authConfig?.MAILER_OTP_EXP > 3600 && (
  48. <Alert className="flex w-full items-center justify-between my-3" variant="warning">
  49. <WarningIcon />
  50. <div>
  51. <AlertTitle>OTP expiry exceeds recommended threshold</AlertTitle>
  52. <AlertDescription className="flex flex-col gap-y-3">
  53. <p>
  54. We have detected that you have enabled the email provider with the OTP expiry
  55. set to more than an hour. It is recommended to set this value to less than an
  56. hour.
  57. </p>
  58. <Button asChild type="default" className="w-min" icon={<ExternalLink />}>
  59. <Link href="https://supabase.com/docs/guides/platform/going-into-prod#security">
  60. View security recommendations
  61. </Link>
  62. </Button>
  63. </AlertDescription>
  64. </div>
  65. </Alert>
  66. )}
  67. <ResourceList>
  68. {isLoading &&
  69. PROVIDERS_SCHEMAS.map((provider) => (
  70. <div
  71. key={`provider_${provider.title}`}
  72. className="py-4 px-6 border-b last:border-b-none"
  73. >
  74. <HorizontalShimmerWithIcon />
  75. </div>
  76. ))}
  77. {isSuccess &&
  78. PROVIDERS_SCHEMAS.map((provider) => {
  79. const providerSchema =
  80. provider.title === 'Phone'
  81. ? {
  82. ...provider,
  83. validationSchema: getPhoneProviderValidationSchema(authConfig),
  84. }
  85. : provider
  86. let isActive = false
  87. if (providerSchema.title === 'SAML 2.0') {
  88. isActive = authConfig && (authConfig as any)['SAML_ENABLED']
  89. } else if (providerSchema.title === 'LinkedIn (OIDC)') {
  90. isActive = authConfig && (authConfig as any)['EXTERNAL_LINKEDIN_OIDC_ENABLED']
  91. } else if (providerSchema.title === 'Slack (OIDC)') {
  92. isActive = authConfig && (authConfig as any)['EXTERNAL_SLACK_OIDC_ENABLED']
  93. } else if (providerSchema.title.includes('Web3')) {
  94. isActive = authConfig && (authConfig as any)['EXTERNAL_WEB3_SOLANA_ENABLED']
  95. } else if (providerSchema.title.includes('X / Twitter (OAuth 2.0)')) {
  96. isActive = authConfig && (authConfig as any)['EXTERNAL_X_ENABLED']
  97. } else if (providerSchema.title === 'Twitter (Deprecated)') {
  98. isActive = authConfig && (authConfig as any)['EXTERNAL_TWITTER_ENABLED']
  99. } else {
  100. isActive =
  101. authConfig &&
  102. (authConfig as any)[`EXTERNAL_${providerSchema.title.toUpperCase()}_ENABLED`]
  103. }
  104. return (
  105. <ProviderForm
  106. key={`provider_${providerSchema.title}`}
  107. config={authConfig!}
  108. provider={providerSchema as unknown as Provider}
  109. isActive={isActive}
  110. />
  111. )
  112. })}
  113. </ResourceList>
  114. </div>
  115. )}
  116. </PageSectionContent>
  117. </PageSection>
  118. )
  119. }