1- import { useReverification , useSession , useUser } from '@clerk/shared/react' ;
2- import type { CreateMeEnterpriseConnectionParams , EnterpriseConnectionResource } from '@clerk/shared/types' ;
1+ import type { EnterpriseConnectionResource } from '@clerk/shared/types' ;
32import React , { type PropsWithChildren } from 'react' ;
43
54import { deriveInitialStep } from './deriveInitialStep' ;
@@ -25,69 +24,33 @@ export interface ConfigureSSOData {
2524 * connection has been created.
2625 */
2726 setProvider : ( provider : ProviderType ) => void ;
28- /**
29- * Creates the enterprise connection for the supplied provider, the user's
30- * primary email domain, and the session's active organization. No-ops when
31- * an enterprise connection already exists so callers can safely re-trigger.
32- */
33- createConnection : ( provider : ProviderType ) => Promise < void > ;
3427}
3528
3629interface ConfigureSSOProviderProps {
3730 enterpriseConnection : EnterpriseConnectionResource | undefined ;
38- createEnterpriseConnection : (
39- params : CreateMeEnterpriseConnectionParams ,
40- ) => Promise < EnterpriseConnectionResource | undefined > ;
4131}
4232
4333const ConfigureSSOContext = React . createContext < ConfigureSSOData | null > ( null ) ;
4434ConfigureSSOContext . displayName = 'ConfigureSSOContext' ;
4535
4636export const ConfigureSSOProvider = ( {
4737 enterpriseConnection,
48- createEnterpriseConnection,
4938 children,
5039} : PropsWithChildren < ConfigureSSOProviderProps > ) : JSX . Element => {
51- const { user } = useUser ( ) ;
52- const { session } = useSession ( ) ;
5340 const [ provider , setProvider ] = React . useState < ProviderType | undefined > (
5441 enterpriseConnection ?. provider as ProviderType ,
5542 ) ;
5643
5744 const initialStepId = deriveInitialStep ( enterpriseConnection ) ;
5845
59- const createConnectionFetcher = React . useCallback (
60- async ( selectedProvider : ProviderType ) => {
61- if ( enterpriseConnection ) {
62- return ;
63- }
64- if ( ! user ?. primaryEmailAddress ) {
65- throw new Error ( 'Primary email required' ) ;
66- }
67-
68- const emailDomain = user . primaryEmailAddress . emailAddress . split ( '@' ) [ 1 ] ;
69- const organizationId = session ?. lastActiveOrganizationId ?? null ;
70-
71- await createEnterpriseConnection ( {
72- provider : selectedProvider ,
73- name : emailDomain ,
74- organizationId,
75- } ) ;
76- } ,
77- [ enterpriseConnection , user , session , createEnterpriseConnection ] ,
78- ) ;
79-
80- const createConnection = useReverification ( createConnectionFetcher ) ;
81-
8246 const value = React . useMemo < ConfigureSSOData > (
8347 ( ) => ( {
8448 initialStepId,
8549 enterpriseConnection,
8650 provider,
8751 setProvider,
88- createConnection,
8952 } ) ,
90- [ initialStepId , enterpriseConnection , provider , createConnection ] ,
53+ [ initialStepId , enterpriseConnection , provider ] ,
9154 ) ;
9255
9356 return < ConfigureSSOContext . Provider value = { value } > { children } </ ConfigureSSOContext . Provider > ;
0 commit comments