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