@@ -99,7 +99,6 @@ import { allSettled, handleValueOrFn, noop } from '@clerk/shared/utils';
9999import type { QueryClient } from '@tanstack/query-core' ;
100100
101101import { debugLogger , initDebugLogger } from '@/utils/debug' ;
102- import { CLERK_ENVIRONMENT_SETTING_PROMPT_REJECTED_KEY , SafeSessionStorage } from '@/utils/sessionStorage' ;
103102
104103import type { MountComponentRenderer } from '../ui/Components' ;
105104import {
@@ -744,32 +743,26 @@ export class Clerk implements ClerkInterface {
744743
745744 public __internal_attemptToEnableEnvironmentSetting = (
746745 params : __internal_AttemptToEnableEnvironmentSettingParams ,
747- ) : { status : 'enabled' | 'prompt-shown' | 'rejected' } => {
748- const { for : setting , caller, onSuccess } = params ;
746+ ) : { status : 'enabled' | 'prompt-shown' } => {
747+ const { for : setting , caller } = params ;
749748
750749 // If not in development instance, return enabled status in order to not open the in-app prompt
751750 if ( this . #instanceType !== 'development' ) {
752751 return { status : 'enabled' } ;
753752 }
754753
755- const rejectedCallers = SafeSessionStorage . getItem < string [ ] > ( CLERK_ENVIRONMENT_SETTING_PROMPT_REJECTED_KEY , [ ] ) ;
756-
757754 switch ( setting ) {
758755 case 'organizations' :
759756 if ( ! disabledOrganizationsFeature ( this , this . environment ) ) {
760757 return { status : 'enabled' } ;
761758 }
762759
763- if ( rejectedCallers . includes ( caller ) ) {
764- return { status : 'rejected' } ;
765- }
766-
767760 this . __internal_openEnableOrganizationsPrompt ( {
768761 caller,
762+ // Reload current window to all invalidate all resources
763+ // related to organizations, eg: roles
769764 onSuccess : ( ) => window . location . reload ( ) ,
770- onClose : ( ) => {
771- SafeSessionStorage . setItem ( CLERK_ENVIRONMENT_SETTING_PROMPT_REJECTED_KEY , [ caller ] ) ;
772- } ,
765+ onClose : params . onClose ,
773766 } as __internal_EnableOrganizationsPromptProps ) ;
774767
775768 return { status : 'prompt-shown' } ;
@@ -865,17 +858,13 @@ export class Clerk implements ClerkInterface {
865858 const { status } = this . __internal_attemptToEnableEnvironmentSetting ( {
866859 for : 'organizations' ,
867860 caller : 'OrganizationProfile' ,
868- onSuccess : ( ) => {
869- this . openOrganizationProfile ( props ) ;
861+ onClose : ( ) => {
862+ throw new ClerkRuntimeError ( warnings . cannotRenderAnyOrganizationComponent ( 'OrganizationProfile' ) , {
863+ code : CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE ,
864+ } ) ;
870865 } ,
871866 } ) ;
872867
873- if ( status === 'rejected' ) {
874- throw new ClerkRuntimeError ( warnings . cannotRenderAnyOrganizationComponent ( 'OrganizationProfile' ) , {
875- code : CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE ,
876- } ) ;
877- }
878-
879868 if ( status === 'prompt-shown' ) {
880869 return ;
881870 }
@@ -906,17 +895,13 @@ export class Clerk implements ClerkInterface {
906895 const { status } = this . __internal_attemptToEnableEnvironmentSetting ( {
907896 for : 'organizations' ,
908897 caller : 'CreateOrganization' ,
909- onSuccess : ( ) => {
910- this . openCreateOrganization ( props ) ;
898+ onClose : ( ) => {
899+ throw new ClerkRuntimeError ( warnings . cannotRenderAnyOrganizationComponent ( 'CreateOrganization' ) , {
900+ code : CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE ,
901+ } ) ;
911902 } ,
912903 } ) ;
913904
914- if ( status === 'rejected' ) {
915- throw new ClerkRuntimeError ( warnings . cannotRenderAnyOrganizationComponent ( 'CreateOrganization' ) , {
916- code : CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE ,
917- } ) ;
918- }
919-
920905 if ( status === 'prompt-shown' ) {
921906 return ;
922907 }
@@ -1059,17 +1044,13 @@ export class Clerk implements ClerkInterface {
10591044 const { status } = this . __internal_attemptToEnableEnvironmentSetting ( {
10601045 for : 'organizations' ,
10611046 caller : 'OrganizationProfile' ,
1062- onSuccess : ( ) => {
1063- this . mountOrganizationProfile ( node , props ) ;
1047+ onClose : ( ) => {
1048+ throw new ClerkRuntimeError ( warnings . cannotRenderAnyOrganizationComponent ( 'OrganizationProfile' ) , {
1049+ code : CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE ,
1050+ } ) ;
10641051 } ,
10651052 } ) ;
10661053
1067- if ( status === 'rejected' ) {
1068- throw new ClerkRuntimeError ( warnings . cannotRenderAnyOrganizationComponent ( 'OrganizationProfile' ) , {
1069- code : CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE ,
1070- } ) ;
1071- }
1072-
10731054 if ( status === 'prompt-shown' ) {
10741055 return ;
10751056 }
@@ -1110,17 +1091,13 @@ export class Clerk implements ClerkInterface {
11101091 const { status } = this . __internal_attemptToEnableEnvironmentSetting ( {
11111092 for : 'organizations' ,
11121093 caller : 'CreateOrganization' ,
1113- onSuccess : ( ) => {
1114- this . mountCreateOrganization ( node , props ) ;
1094+ onClose : ( ) => {
1095+ throw new ClerkRuntimeError ( warnings . cannotRenderAnyOrganizationComponent ( 'CreateOrganization' ) , {
1096+ code : CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE ,
1097+ } ) ;
11151098 } ,
11161099 } ) ;
11171100
1118- if ( status === 'rejected' ) {
1119- throw new ClerkRuntimeError ( warnings . cannotRenderAnyOrganizationComponent ( 'CreateOrganization' ) , {
1120- code : CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE ,
1121- } ) ;
1122- }
1123-
11241101 if ( status === 'prompt-shown' ) {
11251102 return ;
11261103 }
@@ -1152,17 +1129,13 @@ export class Clerk implements ClerkInterface {
11521129 const { status } = this . __internal_attemptToEnableEnvironmentSetting ( {
11531130 for : 'organizations' ,
11541131 caller : 'OrganizationSwitcher' ,
1155- onSuccess : ( ) => {
1156- this . mountOrganizationSwitcher ( node , props ) ;
1132+ onClose : ( ) => {
1133+ throw new ClerkRuntimeError ( warnings . cannotRenderAnyOrganizationComponent ( 'OrganizationSwitcher' ) , {
1134+ code : CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE ,
1135+ } ) ;
11571136 } ,
11581137 } ) ;
11591138
1160- if ( status === 'rejected' ) {
1161- throw new ClerkRuntimeError ( warnings . cannotRenderAnyOrganizationComponent ( 'OrganizationSwitcher' ) , {
1162- code : CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE ,
1163- } ) ;
1164- }
1165-
11661139 if ( status === 'prompt-shown' ) {
11671140 return ;
11681141 }
@@ -1202,17 +1175,13 @@ export class Clerk implements ClerkInterface {
12021175 const { status } = this . __internal_attemptToEnableEnvironmentSetting ( {
12031176 for : 'organizations' ,
12041177 caller : 'OrganizationList' ,
1205- onSuccess : ( ) => {
1206- this . mountOrganizationList ( node , props ) ;
1178+ onClose : ( ) => {
1179+ throw new ClerkRuntimeError ( warnings . cannotRenderAnyOrganizationComponent ( 'OrganizationList' ) , {
1180+ code : CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE ,
1181+ } ) ;
12071182 } ,
12081183 } ) ;
12091184
1210- if ( status === 'rejected' ) {
1211- throw new ClerkRuntimeError ( warnings . cannotRenderAnyOrganizationComponent ( 'OrganizationList' ) , {
1212- code : CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE ,
1213- } ) ;
1214- }
1215-
12161185 if ( status === 'prompt-shown' ) {
12171186 return ;
12181187 }
@@ -1399,17 +1368,13 @@ export class Clerk implements ClerkInterface {
13991368 const { status } = this . __internal_attemptToEnableEnvironmentSetting ( {
14001369 for : 'organizations' ,
14011370 caller : 'TaskChooseOrganization' ,
1402- onSuccess : ( ) => {
1403- this . mountTaskChooseOrganization ( node , props ) ;
1371+ onClose : ( ) => {
1372+ throw new ClerkRuntimeError ( warnings . cannotRenderAnyOrganizationComponent ( 'TaskChooseOrganization' ) , {
1373+ code : CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE ,
1374+ } ) ;
14041375 } ,
14051376 } ) ;
14061377
1407- if ( status === 'rejected' ) {
1408- throw new ClerkRuntimeError ( warnings . cannotRenderAnyOrganizationComponent ( 'TaskChooseOrganization' ) , {
1409- code : CANNOT_RENDER_ORGANIZATIONS_DISABLED_ERROR_CODE ,
1410- } ) ;
1411- }
1412-
14131378 if ( status === 'prompt-shown' ) {
14141379 return ;
14151380 }
0 commit comments