ThirdPartyAuthForm.utils.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import { ThirdPartyAuthIntegration } from '@/data/third-party-auth/integrations-query'
  2. import { BASE_PATH } from '@/lib/constants'
  3. export const INTEGRATION_TYPES = [
  4. 'firebase',
  5. 'auth0',
  6. 'awsCognito',
  7. 'clerk',
  8. 'workos',
  9. 'custom',
  10. ] as const
  11. export type INTEGRATION_TYPES = (typeof INTEGRATION_TYPES)[number]
  12. export const getIntegrationType = (integration?: ThirdPartyAuthIntegration): INTEGRATION_TYPES => {
  13. if (integration?.type === 'workos') {
  14. return 'workos'
  15. }
  16. // TODO(hf): Move these to check type as well.
  17. if (integration?.oidc_issuer_url?.startsWith('https://securetoken.google.com/')) {
  18. return 'firebase'
  19. }
  20. if (integration?.oidc_issuer_url?.includes('amazonaws.com')) {
  21. return 'awsCognito'
  22. }
  23. if (integration?.oidc_issuer_url?.includes('auth0.com')) {
  24. return 'auth0'
  25. }
  26. if (
  27. integration?.oidc_issuer_url?.includes('.clerk.accounts.dev') ||
  28. integration?.oidc_issuer_url?.startsWith('https://clerk.')
  29. ) {
  30. return 'clerk'
  31. }
  32. return 'custom'
  33. }
  34. export const getIntegrationTypeLabel = (type: INTEGRATION_TYPES) => {
  35. switch (type) {
  36. case 'firebase':
  37. return 'Firebase'
  38. case 'auth0':
  39. return 'Auth0'
  40. case 'awsCognito':
  41. return 'Amazon Cognito'
  42. case 'clerk':
  43. return 'Clerk'
  44. case 'workos':
  45. return 'WorkOS'
  46. case 'custom':
  47. default:
  48. return 'Custom'
  49. }
  50. }
  51. export const getIntegrationTypeIcon = (type: INTEGRATION_TYPES) => {
  52. switch (type) {
  53. case 'firebase':
  54. return `${BASE_PATH}/img/icons/firebase-icon.svg`
  55. case 'auth0':
  56. return `${BASE_PATH}/img/icons/auth0-icon.svg`
  57. case 'awsCognito':
  58. return `${BASE_PATH}/img/icons/cognito-icon.svg`
  59. case 'clerk':
  60. return `${BASE_PATH}/img/icons/clerk-icon.svg`
  61. case 'workos':
  62. return `${BASE_PATH}/img/icons/workos-icon.svg`
  63. case 'custom':
  64. default:
  65. return `${BASE_PATH}/img/icons/cognito-icon.svg`
  66. }
  67. }