@jmruthers/pace-core 0.6.2 → 0.6.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +45 -0
- package/cursor-rules/00-pace-core-compliance.mdc +34 -2
- package/dist/{AuthService-BPvc3Ka0.d.ts → AuthService-Cb34EQs3.d.ts} +9 -1
- package/dist/{DataTable-TPTKCX4D.js → DataTable-THFPBKTP.js} +9 -8
- package/dist/{PublicPageProvider-DC6kCaqf.d.ts → PublicPageProvider-DEMpysFR.d.ts} +45 -67
- package/dist/{UnifiedAuthProvider-CVcTjx-d.d.ts → UnifiedAuthProvider-CKvHP1MK.d.ts} +1 -8
- package/dist/{UnifiedAuthProvider-CH6Z342H.js → UnifiedAuthProvider-KAGUYQ4J.js} +5 -4
- package/dist/{api-MVVQZLJI.js → api-IAGWF3ZG.js} +10 -10
- package/dist/{audit-B5P6FFIR.js → audit-V53FV5AG.js} +2 -2
- package/dist/{chunk-SFZUDBL5.js → chunk-2T2IG7T7.js} +70 -56
- package/dist/chunk-2T2IG7T7.js.map +1 -0
- package/dist/{chunk-MMZ7JXPU.js → chunk-6Z7LTB3D.js} +13 -21
- package/dist/{chunk-MMZ7JXPU.js.map → chunk-6Z7LTB3D.js.map} +1 -1
- package/dist/{chunk-6J4GEEJR.js → chunk-CNCQDFLN.js} +53 -27
- package/dist/chunk-CNCQDFLN.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/{chunk-EHMR7VYL.js → chunk-DWUBLJJM.js} +361 -187
- package/dist/chunk-DWUBLJJM.js.map +1 -0
- package/dist/{chunk-2UOI2FG5.js → chunk-HFZBI76P.js} +4 -4
- package/dist/{chunk-F2IMUDXZ.js → chunk-M7MPQISP.js} +2 -2
- package/dist/{chunk-3XC4CPTD.js → chunk-PQBSKX33.js} +244 -5727
- package/dist/chunk-PQBSKX33.js.map +1 -0
- package/dist/chunk-QRPVRXYT.js +226 -0
- package/dist/chunk-QRPVRXYT.js.map +1 -0
- package/dist/{chunk-24UVZUZG.js → chunk-RWEBCB47.js} +129 -387
- package/dist/chunk-RWEBCB47.js.map +1 -0
- package/dist/{chunk-XWQCNGTQ.js → chunk-YDQHOZNA.js} +173 -79
- package/dist/chunk-YDQHOZNA.js.map +1 -0
- package/dist/{chunk-NECFR5MM.js → chunk-ZNIWI3UC.js} +562 -644
- package/dist/chunk-ZNIWI3UC.js.map +1 -0
- package/dist/components.d.ts +2 -2
- package/dist/components.js +12 -13
- package/dist/contextValidator-3JNZKUTX.js +9 -0
- package/dist/contextValidator-3JNZKUTX.js.map +1 -0
- package/dist/eslint-rules/pace-core-compliance.cjs +106 -0
- package/dist/hooks.d.ts +2 -2
- package/dist/hooks.js +7 -6
- package/dist/hooks.js.map +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +21 -16
- package/dist/index.js.map +1 -1
- package/dist/providers.d.ts +3 -3
- package/dist/providers.js +4 -3
- package/dist/rbac/index.d.ts +67 -27
- package/dist/rbac/index.js +15 -8
- package/dist/styles/index.js +1 -1
- package/dist/theming/runtime.js +1 -1
- package/dist/types.js +1 -1
- package/dist/{usePublicRouteParams-1oMokgLF.d.ts → usePublicRouteParams-i3qtoBgg.d.ts} +7 -16
- package/dist/utils.js +5 -7
- package/dist/utils.js.map +1 -1
- package/docs/api/README.md +14 -16
- package/docs/api/modules.md +3796 -2513
- package/docs/components/context-selector.md +126 -0
- package/docs/migration/RBAC_SCOPE_MIGRATION.md +385 -0
- package/docs/pace-mint-fix-auto-selection.md +218 -0
- package/docs/pace-mint-rbac-setup.md +391 -0
- package/docs/rbac/secure-client-protection.md +330 -0
- package/package.json +3 -3
- package/scripts/audit/core/checks/compliance.cjs +72 -0
- package/scripts/audit/core/checks/dependencies.cjs +559 -28
- package/scripts/audit/core/checks/documentation.cjs +68 -3
- package/scripts/audit/core/checks/environment.cjs +2 -14
- package/scripts/audit/core/checks/error-handling.cjs +47 -6
- package/src/components/ContextSelector/ContextSelector.tsx +384 -0
- package/src/components/ContextSelector/index.ts +3 -0
- package/src/components/DataTable/components/RowComponent.tsx +19 -19
- package/src/components/DataTable/components/UnifiedTableBody.tsx +2 -2
- package/src/components/DataTable/hooks/useDataTablePermissions.ts +8 -6
- package/src/components/Dialog/Dialog.tsx +29 -1
- package/src/components/FileDisplay/FileDisplay.tsx +42 -10
- package/src/components/Header/Header.test.tsx +43 -73
- package/src/components/Header/Header.tsx +44 -45
- package/src/components/PaceAppLayout/PaceAppLayout.integration.test.tsx +10 -19
- package/src/components/PaceAppLayout/PaceAppLayout.performance.test.tsx +2 -2
- package/src/components/PaceAppLayout/PaceAppLayout.security.test.tsx +5 -5
- package/src/components/PaceAppLayout/PaceAppLayout.test.tsx +9 -9
- package/src/components/PaceAppLayout/PaceAppLayout.tsx +135 -33
- package/src/components/PaceAppLayout/README.md +14 -17
- package/src/components/PaceAppLayout/test-setup.tsx +2 -2
- package/src/components/index.ts +5 -5
- package/src/eslint-rules/pace-core-compliance.cjs +106 -0
- package/src/hooks/__tests__/useAppConfig.unit.test.ts +4 -98
- package/src/hooks/useAppConfig.ts +15 -30
- package/src/hooks/useFileDisplay.ts +77 -50
- package/src/index.ts +4 -5
- package/src/providers/services/AuthServiceProvider.tsx +17 -7
- package/src/providers/services/EventServiceProvider.tsx +33 -5
- package/src/providers/services/UnifiedAuthProvider.tsx +90 -134
- package/src/rbac/__tests__/adapters.comprehensive.test.tsx +1 -1
- package/src/rbac/adapters.tsx +2 -2
- package/src/rbac/api.test.ts +59 -51
- package/src/rbac/api.ts +178 -132
- package/src/rbac/components/PagePermissionGuard.tsx +38 -10
- package/src/rbac/hooks/__tests__/useSecureSupabase.test.ts +32 -21
- package/src/rbac/hooks/permissions/useAccessLevel.ts +1 -1
- package/src/rbac/hooks/permissions/useCan.ts +41 -11
- package/src/rbac/hooks/permissions/useHasAllPermissions.ts +1 -1
- package/src/rbac/hooks/permissions/useHasAnyPermission.ts +1 -1
- package/src/rbac/hooks/permissions/useMultiplePermissions.ts +1 -1
- package/src/rbac/hooks/useCan.test.ts +0 -9
- package/src/rbac/hooks/useRBAC.test.ts +1 -5
- package/src/rbac/hooks/useRBAC.ts +36 -37
- package/src/rbac/hooks/useResolvedScope.test.ts +120 -35
- package/src/rbac/hooks/useResolvedScope.ts +35 -40
- package/src/rbac/hooks/useSecureSupabase.ts +7 -7
- package/src/rbac/index.ts +7 -0
- package/src/rbac/secureClient.test.ts +22 -18
- package/src/rbac/secureClient.ts +103 -16
- package/src/rbac/security.ts +0 -17
- package/src/rbac/types.ts +1 -0
- package/src/rbac/utils/__tests__/contextValidator.test.ts +64 -86
- package/src/rbac/utils/clientSecurity.ts +93 -0
- package/src/rbac/utils/contextValidator.ts +77 -168
- package/src/services/AuthService.ts +39 -7
- package/src/services/EventService.ts +186 -54
- package/src/services/OrganisationService.ts +81 -14
- package/src/services/__tests__/EventService.test.ts +1 -2
- package/src/services/base/BaseService.ts +3 -0
- package/src/utils/dynamic/dynamicUtils.ts +7 -4
- package/dist/chunk-24UVZUZG.js.map +0 -1
- package/dist/chunk-3XC4CPTD.js.map +0 -1
- package/dist/chunk-6J4GEEJR.js.map +0 -1
- package/dist/chunk-7D4SUZUM.js +0 -38
- package/dist/chunk-EHMR7VYL.js.map +0 -1
- package/dist/chunk-NECFR5MM.js.map +0 -1
- package/dist/chunk-SFZUDBL5.js.map +0 -1
- package/dist/chunk-XWQCNGTQ.js.map +0 -1
- package/docs/api/classes/ColumnFactory.md +0 -243
- package/docs/api/classes/InvalidScopeError.md +0 -73
- package/docs/api/classes/Logger.md +0 -178
- package/docs/api/classes/MissingUserContextError.md +0 -66
- package/docs/api/classes/OrganisationContextRequiredError.md +0 -66
- package/docs/api/classes/PermissionDeniedError.md +0 -73
- package/docs/api/classes/RBACAuditManager.md +0 -297
- package/docs/api/classes/RBACCache.md +0 -322
- package/docs/api/classes/RBACEngine.md +0 -171
- package/docs/api/classes/RBACError.md +0 -76
- package/docs/api/classes/RBACNotInitializedError.md +0 -66
- package/docs/api/classes/SecureSupabaseClient.md +0 -163
- package/docs/api/classes/StorageUtils.md +0 -328
- package/docs/api/enums/FileCategory.md +0 -184
- package/docs/api/enums/LogLevel.md +0 -54
- package/docs/api/enums/RBACErrorCode.md +0 -228
- package/docs/api/enums/RPCFunction.md +0 -118
- package/docs/api/interfaces/AddressFieldProps.md +0 -241
- package/docs/api/interfaces/AddressFieldRef.md +0 -94
- package/docs/api/interfaces/AggregateConfig.md +0 -43
- package/docs/api/interfaces/AutocompleteOptions.md +0 -75
- package/docs/api/interfaces/AvatarProps.md +0 -128
- package/docs/api/interfaces/BadgeProps.md +0 -34
- package/docs/api/interfaces/ButtonProps.md +0 -56
- package/docs/api/interfaces/CalendarProps.md +0 -73
- package/docs/api/interfaces/CardProps.md +0 -69
- package/docs/api/interfaces/ColorPalette.md +0 -7
- package/docs/api/interfaces/ColorShade.md +0 -66
- package/docs/api/interfaces/ComplianceResult.md +0 -30
- package/docs/api/interfaces/DataAccessRecord.md +0 -96
- package/docs/api/interfaces/DataRecord.md +0 -11
- package/docs/api/interfaces/DataTableAction.md +0 -252
- package/docs/api/interfaces/DataTableColumn.md +0 -504
- package/docs/api/interfaces/DataTableProps.md +0 -625
- package/docs/api/interfaces/DataTableToolbarButton.md +0 -96
- package/docs/api/interfaces/DatabaseComplianceResult.md +0 -85
- package/docs/api/interfaces/DatabaseIssue.md +0 -41
- package/docs/api/interfaces/EmptyStateConfig.md +0 -61
- package/docs/api/interfaces/EnhancedNavigationMenuProps.md +0 -235
- package/docs/api/interfaces/ErrorBoundaryProps.md +0 -147
- package/docs/api/interfaces/ErrorBoundaryProviderProps.md +0 -36
- package/docs/api/interfaces/ErrorBoundaryState.md +0 -75
- package/docs/api/interfaces/EventAppRoleData.md +0 -71
- package/docs/api/interfaces/ExportColumn.md +0 -90
- package/docs/api/interfaces/ExportOptions.md +0 -126
- package/docs/api/interfaces/FileDisplayProps.md +0 -249
- package/docs/api/interfaces/FileMetadata.md +0 -129
- package/docs/api/interfaces/FileReference.md +0 -118
- package/docs/api/interfaces/FileSizeLimits.md +0 -7
- package/docs/api/interfaces/FileUploadOptions.md +0 -139
- package/docs/api/interfaces/FileUploadProps.md +0 -296
- package/docs/api/interfaces/FooterProps.md +0 -107
- package/docs/api/interfaces/FormFieldProps.md +0 -166
- package/docs/api/interfaces/FormProps.md +0 -113
- package/docs/api/interfaces/GrantEventAppRoleParams.md +0 -122
- package/docs/api/interfaces/InactivityWarningModalProps.md +0 -115
- package/docs/api/interfaces/InputProps.md +0 -56
- package/docs/api/interfaces/LabelProps.md +0 -107
- package/docs/api/interfaces/LoggerConfig.md +0 -62
- package/docs/api/interfaces/LoginFormProps.md +0 -187
- package/docs/api/interfaces/NavigationAccessRecord.md +0 -107
- package/docs/api/interfaces/NavigationContextType.md +0 -164
- package/docs/api/interfaces/NavigationGuardProps.md +0 -139
- package/docs/api/interfaces/NavigationItem.md +0 -120
- package/docs/api/interfaces/NavigationMenuProps.md +0 -221
- package/docs/api/interfaces/NavigationProviderProps.md +0 -117
- package/docs/api/interfaces/Organisation.md +0 -140
- package/docs/api/interfaces/OrganisationContextType.md +0 -388
- package/docs/api/interfaces/OrganisationMembership.md +0 -140
- package/docs/api/interfaces/OrganisationProviderProps.md +0 -76
- package/docs/api/interfaces/OrganisationSecurityError.md +0 -62
- package/docs/api/interfaces/PaceAppLayoutProps.md +0 -409
- package/docs/api/interfaces/PaceLoginPageProps.md +0 -49
- package/docs/api/interfaces/PageAccessRecord.md +0 -85
- package/docs/api/interfaces/PagePermissionContextType.md +0 -140
- package/docs/api/interfaces/PagePermissionGuardProps.md +0 -153
- package/docs/api/interfaces/PagePermissionProviderProps.md +0 -119
- package/docs/api/interfaces/PaletteData.md +0 -41
- package/docs/api/interfaces/ParsedAddress.md +0 -120
- package/docs/api/interfaces/PermissionEnforcerProps.md +0 -153
- package/docs/api/interfaces/ProgressProps.md +0 -42
- package/docs/api/interfaces/ProtectedRouteProps.md +0 -78
- package/docs/api/interfaces/PublicPageFooterProps.md +0 -112
- package/docs/api/interfaces/PublicPageHeaderProps.md +0 -125
- package/docs/api/interfaces/PublicPageLayoutProps.md +0 -185
- package/docs/api/interfaces/QuickFix.md +0 -52
- package/docs/api/interfaces/RBACAccessValidateParams.md +0 -52
- package/docs/api/interfaces/RBACAccessValidateResult.md +0 -41
- package/docs/api/interfaces/RBACAuditLogParams.md +0 -85
- package/docs/api/interfaces/RBACAuditLogResult.md +0 -52
- package/docs/api/interfaces/RBACConfig.md +0 -133
- package/docs/api/interfaces/RBACContext.md +0 -52
- package/docs/api/interfaces/RBACLogger.md +0 -112
- package/docs/api/interfaces/RBACPageAccessCheckParams.md +0 -74
- package/docs/api/interfaces/RBACPerformanceMetrics.md +0 -138
- package/docs/api/interfaces/RBACPermissionCheckParams.md +0 -74
- package/docs/api/interfaces/RBACPermissionCheckResult.md +0 -52
- package/docs/api/interfaces/RBACPermissionsGetParams.md +0 -63
- package/docs/api/interfaces/RBACPermissionsGetResult.md +0 -63
- package/docs/api/interfaces/RBACResult.md +0 -58
- package/docs/api/interfaces/RBACRoleGrantParams.md +0 -63
- package/docs/api/interfaces/RBACRoleGrantResult.md +0 -52
- package/docs/api/interfaces/RBACRoleRevokeParams.md +0 -63
- package/docs/api/interfaces/RBACRoleRevokeResult.md +0 -52
- package/docs/api/interfaces/RBACRoleValidateParams.md +0 -52
- package/docs/api/interfaces/RBACRoleValidateResult.md +0 -63
- package/docs/api/interfaces/RBACRolesListParams.md +0 -52
- package/docs/api/interfaces/RBACRolesListResult.md +0 -74
- package/docs/api/interfaces/RBACSessionTrackParams.md +0 -74
- package/docs/api/interfaces/RBACSessionTrackResult.md +0 -52
- package/docs/api/interfaces/ResourcePermissions.md +0 -155
- package/docs/api/interfaces/RevokeEventAppRoleParams.md +0 -100
- package/docs/api/interfaces/RoleBasedRouterContextType.md +0 -151
- package/docs/api/interfaces/RoleBasedRouterProps.md +0 -156
- package/docs/api/interfaces/RoleManagementResult.md +0 -52
- package/docs/api/interfaces/RouteAccessRecord.md +0 -107
- package/docs/api/interfaces/RouteConfig.md +0 -134
- package/docs/api/interfaces/RuntimeComplianceResult.md +0 -55
- package/docs/api/interfaces/SecureDataContextType.md +0 -168
- package/docs/api/interfaces/SecureDataProviderProps.md +0 -132
- package/docs/api/interfaces/SessionRestorationLoaderProps.md +0 -34
- package/docs/api/interfaces/SetupIssue.md +0 -41
- package/docs/api/interfaces/StorageConfig.md +0 -41
- package/docs/api/interfaces/StorageFileInfo.md +0 -74
- package/docs/api/interfaces/StorageFileMetadata.md +0 -151
- package/docs/api/interfaces/StorageListOptions.md +0 -99
- package/docs/api/interfaces/StorageListResult.md +0 -41
- package/docs/api/interfaces/StorageUploadOptions.md +0 -101
- package/docs/api/interfaces/StorageUploadResult.md +0 -63
- package/docs/api/interfaces/StorageUrlOptions.md +0 -60
- package/docs/api/interfaces/StyleImport.md +0 -19
- package/docs/api/interfaces/SwitchProps.md +0 -34
- package/docs/api/interfaces/TabsContentProps.md +0 -9
- package/docs/api/interfaces/TabsListProps.md +0 -9
- package/docs/api/interfaces/TabsProps.md +0 -9
- package/docs/api/interfaces/TabsTriggerProps.md +0 -50
- package/docs/api/interfaces/TextareaProps.md +0 -53
- package/docs/api/interfaces/ToastActionElement.md +0 -12
- package/docs/api/interfaces/ToastProps.md +0 -9
- package/docs/api/interfaces/UnifiedAuthContextType.md +0 -823
- package/docs/api/interfaces/UnifiedAuthProviderProps.md +0 -173
- package/docs/api/interfaces/UseFormDialogOptions.md +0 -62
- package/docs/api/interfaces/UseFormDialogReturn.md +0 -117
- package/docs/api/interfaces/UseInactivityTrackerOptions.md +0 -138
- package/docs/api/interfaces/UseInactivityTrackerReturn.md +0 -123
- package/docs/api/interfaces/UsePublicEventLogoOptions.md +0 -87
- package/docs/api/interfaces/UsePublicEventLogoReturn.md +0 -84
- package/docs/api/interfaces/UsePublicEventOptions.md +0 -34
- package/docs/api/interfaces/UsePublicEventReturn.md +0 -71
- package/docs/api/interfaces/UsePublicFileDisplayOptions.md +0 -47
- package/docs/api/interfaces/UsePublicFileDisplayReturn.md +0 -123
- package/docs/api/interfaces/UsePublicRouteParamsReturn.md +0 -97
- package/docs/api/interfaces/UseResolvedScopeOptions.md +0 -47
- package/docs/api/interfaces/UseResolvedScopeReturn.md +0 -47
- package/docs/api/interfaces/UseResourcePermissionsOptions.md +0 -34
- package/docs/api/interfaces/UserEventAccess.md +0 -121
- package/docs/api/interfaces/UserMenuProps.md +0 -88
- package/docs/api/interfaces/UserProfile.md +0 -63
- package/src/components/EventSelector/EventSelector.test.tsx +0 -720
- package/src/components/EventSelector/EventSelector.tsx +0 -423
- package/src/components/EventSelector/index.ts +0 -3
- package/src/components/OrganisationSelector/OrganisationSelector.test.tsx +0 -784
- package/src/components/OrganisationSelector/OrganisationSelector.tsx +0 -327
- package/src/components/OrganisationSelector/index.ts +0 -9
- /package/dist/{DataTable-TPTKCX4D.js.map → DataTable-THFPBKTP.js.map} +0 -0
- /package/dist/{UnifiedAuthProvider-CH6Z342H.js.map → UnifiedAuthProvider-KAGUYQ4J.js.map} +0 -0
- /package/dist/{api-MVVQZLJI.js.map → api-IAGWF3ZG.js.map} +0 -0
- /package/dist/{audit-B5P6FFIR.js.map → audit-V53FV5AG.js.map} +0 -0
- /package/dist/{chunk-7D4SUZUM.js.map → chunk-DGUM43GV.js.map} +0 -0
- /package/dist/{chunk-2UOI2FG5.js.map → chunk-HFZBI76P.js.map} +0 -0
- /package/dist/{chunk-F2IMUDXZ.js.map → chunk-M7MPQISP.js.map} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
} from "./chunk-
|
|
2
|
+
isRBACInitialized,
|
|
3
|
+
setupRBAC
|
|
4
|
+
} from "./chunk-RWEBCB47.js";
|
|
5
5
|
import {
|
|
6
6
|
assertOrganisationId,
|
|
7
7
|
assertUserId
|
|
@@ -16,10 +16,10 @@ import {
|
|
|
16
16
|
} from "./chunk-PWLANIRT.js";
|
|
17
17
|
|
|
18
18
|
// src/providers/services/UnifiedAuthProvider.tsx
|
|
19
|
-
import { createContext as createContext5, useContext as useContext6, useMemo as useMemo6, useCallback, useRef as
|
|
19
|
+
import { createContext as createContext5, useContext as useContext6, useMemo as useMemo6, useCallback, useRef as useRef9, useEffect as useEffect10, useState as useState3, useReducer as useReducer5 } from "react";
|
|
20
20
|
|
|
21
21
|
// src/providers/services/AuthServiceProvider.tsx
|
|
22
|
-
import { createContext, useMemo, useEffect, useState } from "react";
|
|
22
|
+
import { createContext, useMemo, useEffect, useState, useRef } from "react";
|
|
23
23
|
|
|
24
24
|
// src/services/AuthService.ts
|
|
25
25
|
import { AuthError } from "@supabase/supabase-js";
|
|
@@ -49,6 +49,9 @@ var BaseService = class {
|
|
|
49
49
|
* This triggers React re-renders
|
|
50
50
|
*/
|
|
51
51
|
notify() {
|
|
52
|
+
const serviceName = this.constructor.name;
|
|
53
|
+
const instanceId = this.instanceId || "unknown";
|
|
54
|
+
logger.debug("BaseService", `[${serviceName} ID:${instanceId}] Notifying ${this.subscribers.length} subscribers`);
|
|
52
55
|
this.subscribers.forEach((callback) => {
|
|
53
56
|
try {
|
|
54
57
|
callback();
|
|
@@ -93,7 +96,7 @@ var BaseService = class {
|
|
|
93
96
|
};
|
|
94
97
|
|
|
95
98
|
// src/services/AuthService.ts
|
|
96
|
-
var
|
|
99
|
+
var _AuthService = class _AuthService extends BaseService {
|
|
97
100
|
constructor(supabaseClient, appName) {
|
|
98
101
|
super();
|
|
99
102
|
this.user = null;
|
|
@@ -113,11 +116,21 @@ var AuthService = class extends BaseService {
|
|
|
113
116
|
this.appName = void 0;
|
|
114
117
|
this.errorHandler = null;
|
|
115
118
|
this.unhandledRejectionHandler = null;
|
|
119
|
+
this.instanceId = ++_AuthService.instanceCount;
|
|
116
120
|
this.supabaseClient = supabaseClient;
|
|
117
121
|
this.appName = appName;
|
|
122
|
+
logger.debug("AuthService", `Instance created [ID:${this.instanceId}]`, { appName });
|
|
123
|
+
}
|
|
124
|
+
getInstanceId() {
|
|
125
|
+
return this.instanceId;
|
|
118
126
|
}
|
|
119
127
|
// Auth state getters
|
|
120
128
|
getUser() {
|
|
129
|
+
if (this.user) {
|
|
130
|
+
logger.debug("AuthService", `getUser() [ID:${this.instanceId}] returning user: ${this.user.id}`);
|
|
131
|
+
} else {
|
|
132
|
+
logger.debug("AuthService", `getUser() [ID:${this.instanceId}] returning null`);
|
|
133
|
+
}
|
|
121
134
|
return this.user;
|
|
122
135
|
}
|
|
123
136
|
getSession() {
|
|
@@ -398,24 +411,29 @@ var AuthService = class extends BaseService {
|
|
|
398
411
|
const subscription = this.supabaseClient.auth.onAuthStateChange(
|
|
399
412
|
(event, session) => {
|
|
400
413
|
try {
|
|
414
|
+
logger.debug("AuthService", `Auth state change [ID:${this.instanceId}]`, {
|
|
415
|
+
event,
|
|
416
|
+
hasSession: !!session,
|
|
417
|
+
userId: session?.user?.id
|
|
418
|
+
});
|
|
401
419
|
if (event === "SIGNED_OUT") {
|
|
402
420
|
this.session = null;
|
|
403
421
|
this.user = null;
|
|
404
422
|
this.authError = null;
|
|
405
423
|
if (session?.user) {
|
|
406
424
|
this.trackSession("logout", session).catch((err) => {
|
|
407
|
-
logger.warn("AuthService",
|
|
425
|
+
logger.warn("AuthService", `Failed to track logout session [ID:${this.instanceId}]:`, err);
|
|
408
426
|
});
|
|
409
427
|
}
|
|
410
428
|
} else if (event === "SIGNED_IN" || event === "TOKEN_REFRESHED") {
|
|
411
429
|
this.session = session;
|
|
412
430
|
this.user = session?.user ?? null;
|
|
413
|
-
if (session) {
|
|
431
|
+
if (session?.user) {
|
|
414
432
|
this.authError = null;
|
|
415
433
|
}
|
|
416
434
|
if (event === "SIGNED_IN" && session?.user) {
|
|
417
435
|
this.trackSession("login", session).catch((err) => {
|
|
418
|
-
logger.warn("AuthService",
|
|
436
|
+
logger.warn("AuthService", `Failed to track login session [ID:${this.instanceId}]:`, err);
|
|
419
437
|
});
|
|
420
438
|
}
|
|
421
439
|
} else if (event === "INITIAL_SESSION") {
|
|
@@ -433,13 +451,22 @@ var AuthService = class extends BaseService {
|
|
|
433
451
|
}
|
|
434
452
|
}
|
|
435
453
|
this.authLoading = false;
|
|
454
|
+
logger.debug("AuthService", `State synchronized after INITIAL_SESSION [ID:${this.instanceId}]`, {
|
|
455
|
+
hasUser: !!this.user,
|
|
456
|
+
userId: this.user?.id
|
|
457
|
+
});
|
|
436
458
|
this.notify();
|
|
437
459
|
return;
|
|
438
460
|
}
|
|
439
461
|
this.authLoading = false;
|
|
462
|
+
logger.debug("AuthService", `State synchronized after event [ID:${this.instanceId}]`, {
|
|
463
|
+
event,
|
|
464
|
+
hasUser: !!this.user,
|
|
465
|
+
userId: this.user?.id
|
|
466
|
+
});
|
|
440
467
|
this.notify();
|
|
441
468
|
} catch (error) {
|
|
442
|
-
logger.warn("AuthService",
|
|
469
|
+
logger.warn("AuthService", `Error in auth state change handler [ID:${this.instanceId}]:`, error);
|
|
443
470
|
this.authLoading = false;
|
|
444
471
|
this.notify();
|
|
445
472
|
}
|
|
@@ -578,15 +605,20 @@ var AuthService = class extends BaseService {
|
|
|
578
605
|
}
|
|
579
606
|
}
|
|
580
607
|
};
|
|
608
|
+
_AuthService.instanceCount = 0;
|
|
609
|
+
var AuthService = _AuthService;
|
|
581
610
|
|
|
582
611
|
// src/providers/services/AuthServiceProvider.tsx
|
|
583
612
|
import { jsx } from "react/jsx-runtime";
|
|
584
613
|
var AuthServiceContext = createContext(null);
|
|
585
614
|
function AuthServiceProvider({ children, supabaseClient, appName }) {
|
|
586
|
-
const
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
615
|
+
const authServiceRef = useRef(null);
|
|
616
|
+
if (!authServiceRef.current) {
|
|
617
|
+
authServiceRef.current = new AuthService(supabaseClient, appName);
|
|
618
|
+
}
|
|
619
|
+
const authService = authServiceRef.current;
|
|
620
|
+
useEffect(() => {
|
|
621
|
+
}, [authService, supabaseClient, appName]);
|
|
590
622
|
const [sessionRestoration, setSessionRestoration] = useState(
|
|
591
623
|
() => authService.getSessionRestorationState()
|
|
592
624
|
);
|
|
@@ -615,10 +647,10 @@ function AuthServiceProvider({ children, supabaseClient, appName }) {
|
|
|
615
647
|
}
|
|
616
648
|
|
|
617
649
|
// src/providers/services/OrganisationServiceProvider.tsx
|
|
618
|
-
import { createContext as createContext2, useMemo as useMemo2, useEffect as useEffect2, useRef } from "react";
|
|
650
|
+
import { createContext as createContext2, useMemo as useMemo2, useEffect as useEffect2, useRef as useRef2 } from "react";
|
|
619
651
|
|
|
620
652
|
// src/services/OrganisationService.ts
|
|
621
|
-
var
|
|
653
|
+
var _OrganisationService = class _OrganisationService extends BaseService {
|
|
622
654
|
constructor(supabaseClient, user, session) {
|
|
623
655
|
super();
|
|
624
656
|
this._selectedOrganisation = null;
|
|
@@ -640,9 +672,17 @@ var OrganisationService = class extends BaseService {
|
|
|
640
672
|
this.lastLoadTimeRef = 0;
|
|
641
673
|
this.hasFailedRef = false;
|
|
642
674
|
this.abortControllerRef = null;
|
|
675
|
+
this.instanceId = ++_OrganisationService.instanceCount;
|
|
643
676
|
this.supabaseClient = supabaseClient;
|
|
644
677
|
this.user = user;
|
|
645
678
|
this.session = session;
|
|
679
|
+
logger.debug("OrganisationService", `Instance created [ID:${this.instanceId}]`, {
|
|
680
|
+
hasUser: !!user,
|
|
681
|
+
userId: user?.id
|
|
682
|
+
});
|
|
683
|
+
}
|
|
684
|
+
getInstanceId() {
|
|
685
|
+
return this.instanceId;
|
|
646
686
|
}
|
|
647
687
|
// Interface implementation
|
|
648
688
|
getSelectedOrganisation() {
|
|
@@ -715,16 +755,35 @@ var OrganisationService = class extends BaseService {
|
|
|
715
755
|
}
|
|
716
756
|
// Update dependencies
|
|
717
757
|
updateDependencies(user, session) {
|
|
718
|
-
const
|
|
719
|
-
const
|
|
720
|
-
|
|
758
|
+
const previousUserId = this.user?.id || null;
|
|
759
|
+
const newUserId = user?.id || null;
|
|
760
|
+
const userChanged = previousUserId !== newUserId;
|
|
761
|
+
const needsRetry = this._error !== null && !this.isLoadingRef;
|
|
762
|
+
const isEmpty = newUserId !== null && this._organisations.length === 0 && !this.isLoadingRef;
|
|
763
|
+
if (userChanged || needsRetry || isEmpty) {
|
|
764
|
+
if (userChanged) {
|
|
765
|
+
logger.debug("OrganisationService", `User changed [ID:${this.instanceId}], resetting initialization`, {
|
|
766
|
+
previousUserId,
|
|
767
|
+
newUserId
|
|
768
|
+
});
|
|
769
|
+
} else if (needsRetry) {
|
|
770
|
+
logger.debug("OrganisationService", `Previous error detected [ID:${this.instanceId}], retrying initialization`);
|
|
771
|
+
} else if (isEmpty) {
|
|
772
|
+
logger.debug("OrganisationService", `No organisations found [ID:${this.instanceId}], retrying initialization`);
|
|
773
|
+
}
|
|
721
774
|
this._isSuperAdmin = false;
|
|
775
|
+
this.resetInitialization();
|
|
776
|
+
if (userChanged) {
|
|
777
|
+
this._organisations = [];
|
|
778
|
+
this._userMemberships = [];
|
|
779
|
+
this._roleMapState = /* @__PURE__ */ new Map();
|
|
780
|
+
this._selectedOrganisation = null;
|
|
781
|
+
this._isContextReady = false;
|
|
782
|
+
}
|
|
783
|
+
this.lastLoadTimeRef = 0;
|
|
722
784
|
}
|
|
723
785
|
this.user = user;
|
|
724
786
|
this.session = session;
|
|
725
|
-
if (wasAuthenticated && !isAuthenticated) {
|
|
726
|
-
this.resetInitialization();
|
|
727
|
-
}
|
|
728
787
|
this.notify();
|
|
729
788
|
}
|
|
730
789
|
// Organisation methods
|
|
@@ -793,6 +852,10 @@ var OrganisationService = class extends BaseService {
|
|
|
793
852
|
}
|
|
794
853
|
// Lifecycle methods
|
|
795
854
|
async initialize() {
|
|
855
|
+
if (!this.user) {
|
|
856
|
+
logger.debug("OrganisationService", "Skipping initialization - no user");
|
|
857
|
+
return;
|
|
858
|
+
}
|
|
796
859
|
await super.initialize();
|
|
797
860
|
if (!this.isLoadingRef) {
|
|
798
861
|
await this.loadUserOrganisations();
|
|
@@ -855,7 +918,7 @@ var OrganisationService = class extends BaseService {
|
|
|
855
918
|
return;
|
|
856
919
|
}
|
|
857
920
|
const now = Date.now();
|
|
858
|
-
if (now - this.lastLoadTimeRef < 2e3) {
|
|
921
|
+
if (this._organisations.length > 0 && now - this.lastLoadTimeRef < 2e3) {
|
|
859
922
|
if (this._organisations.length > 0 || this._selectedOrganisation) {
|
|
860
923
|
this._isLoading = false;
|
|
861
924
|
} else {
|
|
@@ -874,6 +937,9 @@ var OrganisationService = class extends BaseService {
|
|
|
874
937
|
this._isLoading = true;
|
|
875
938
|
this._error = null;
|
|
876
939
|
this.notify();
|
|
940
|
+
logger.debug("OrganisationService", "Loading organisations for user", {
|
|
941
|
+
userId: this.user.id
|
|
942
|
+
});
|
|
877
943
|
try {
|
|
878
944
|
let memberships, membershipError, organisations = [];
|
|
879
945
|
try {
|
|
@@ -932,6 +998,10 @@ var OrganisationService = class extends BaseService {
|
|
|
932
998
|
}
|
|
933
999
|
});
|
|
934
1000
|
organisations = Array.from(organisationsMap.values());
|
|
1001
|
+
logger.debug("OrganisationService", "Query results", {
|
|
1002
|
+
membershipsCount: memberships.length,
|
|
1003
|
+
organisationsCount: organisations.length
|
|
1004
|
+
});
|
|
935
1005
|
} catch (queryError) {
|
|
936
1006
|
if (queryError instanceof Error) {
|
|
937
1007
|
membershipError = queryError;
|
|
@@ -946,7 +1016,15 @@ var OrganisationService = class extends BaseService {
|
|
|
946
1016
|
let userIsSuperAdmin = false;
|
|
947
1017
|
if (this.user?.id) {
|
|
948
1018
|
try {
|
|
949
|
-
|
|
1019
|
+
const { isSuperAdmin: checkSuperAdmin, isRBACInitialized: isRBACInitialized2, setupRBAC: setupRBAC2 } = await import("./api-IAGWF3ZG.js");
|
|
1020
|
+
if (!isRBACInitialized2() && this.supabaseClient) {
|
|
1021
|
+
setupRBAC2(this.supabaseClient);
|
|
1022
|
+
}
|
|
1023
|
+
if (isRBACInitialized2()) {
|
|
1024
|
+
userIsSuperAdmin = await checkSuperAdmin(this.user.id);
|
|
1025
|
+
} else {
|
|
1026
|
+
userIsSuperAdmin = false;
|
|
1027
|
+
}
|
|
950
1028
|
this._isSuperAdmin = userIsSuperAdmin;
|
|
951
1029
|
} catch (error) {
|
|
952
1030
|
logger.warn("OrganisationService", "Failed to check super admin status", { error });
|
|
@@ -997,7 +1075,12 @@ var OrganisationService = class extends BaseService {
|
|
|
997
1075
|
}
|
|
998
1076
|
throw new Error("User has no access to active organisations");
|
|
999
1077
|
}
|
|
1000
|
-
|
|
1078
|
+
const sortedOrgs = [...activeOrgs].sort((a, b) => {
|
|
1079
|
+
const nameA = (a.display_name || a.name || "").toLowerCase();
|
|
1080
|
+
const nameB = (b.display_name || b.name || "").toLowerCase();
|
|
1081
|
+
return nameA.localeCompare(nameB);
|
|
1082
|
+
});
|
|
1083
|
+
this._organisations = sortedOrgs;
|
|
1001
1084
|
this._userMemberships = memberships;
|
|
1002
1085
|
this._roleMapState = roleMap;
|
|
1003
1086
|
let initialOrg = null;
|
|
@@ -1079,6 +1162,8 @@ var OrganisationService = class extends BaseService {
|
|
|
1079
1162
|
this._isContextReady = false;
|
|
1080
1163
|
}
|
|
1081
1164
|
};
|
|
1165
|
+
_OrganisationService.instanceCount = 0;
|
|
1166
|
+
var OrganisationService = _OrganisationService;
|
|
1082
1167
|
|
|
1083
1168
|
// src/providers/services/OrganisationServiceProvider.tsx
|
|
1084
1169
|
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
@@ -1089,7 +1174,7 @@ function OrganisationServiceProvider({
|
|
|
1089
1174
|
user,
|
|
1090
1175
|
session
|
|
1091
1176
|
}) {
|
|
1092
|
-
const organisationServiceRef =
|
|
1177
|
+
const organisationServiceRef = useRef2(null);
|
|
1093
1178
|
if (!organisationServiceRef.current) {
|
|
1094
1179
|
organisationServiceRef.current = new OrganisationService(supabaseClient, user, session);
|
|
1095
1180
|
}
|
|
@@ -1123,10 +1208,10 @@ function OrganisationServiceProvider({
|
|
|
1123
1208
|
}
|
|
1124
1209
|
|
|
1125
1210
|
// src/providers/services/EventServiceProvider.tsx
|
|
1126
|
-
import { createContext as createContext3, useMemo as useMemo3, useEffect as useEffect3, useRef as
|
|
1211
|
+
import { createContext as createContext3, useMemo as useMemo3, useEffect as useEffect3, useRef as useRef3 } from "react";
|
|
1127
1212
|
|
|
1128
1213
|
// src/services/EventService.ts
|
|
1129
|
-
var
|
|
1214
|
+
var _EventService = class _EventService extends BaseService {
|
|
1130
1215
|
constructor(supabaseClient, user, session, appName, selectedOrganisation, setSelectedEventId) {
|
|
1131
1216
|
super();
|
|
1132
1217
|
this.events = [];
|
|
@@ -1143,19 +1228,27 @@ var EventService = class extends BaseService {
|
|
|
1143
1228
|
this.setSelectedEventId = null;
|
|
1144
1229
|
this.isSuperAdmin = false;
|
|
1145
1230
|
// Track super admin status for conditional validation
|
|
1146
|
-
|
|
1147
|
-
// Cache app config to avoid repeated lookups
|
|
1231
|
+
// App config removed - scope is now page-level only (rbac_app_pages.scope_type)
|
|
1148
1232
|
// Internal state management
|
|
1149
1233
|
this.isInitializedRef = false;
|
|
1150
1234
|
this.isFetchingRef = false;
|
|
1151
1235
|
this.hasAutoSelectedRef = false;
|
|
1152
1236
|
this.userClearedEventRef = false;
|
|
1237
|
+
this.instanceId = ++_EventService.instanceCount;
|
|
1153
1238
|
this.supabaseClient = supabaseClient;
|
|
1154
1239
|
this.user = user;
|
|
1155
1240
|
this.session = session;
|
|
1156
1241
|
this.appName = appName;
|
|
1157
1242
|
this.selectedOrganisation = selectedOrganisation;
|
|
1158
1243
|
this.setSelectedEventId = setSelectedEventId;
|
|
1244
|
+
logger.debug("EventService", `Instance created [ID:${this.instanceId}]`, {
|
|
1245
|
+
appName,
|
|
1246
|
+
hasUser: !!user,
|
|
1247
|
+
userId: user?.id
|
|
1248
|
+
});
|
|
1249
|
+
}
|
|
1250
|
+
getInstanceId() {
|
|
1251
|
+
return this.instanceId;
|
|
1159
1252
|
}
|
|
1160
1253
|
// Helper method to get user-scoped storage key
|
|
1161
1254
|
getStorageKey(userId) {
|
|
@@ -1182,6 +1275,11 @@ var EventService = class extends BaseService {
|
|
|
1182
1275
|
this.resetInitialization();
|
|
1183
1276
|
this.isInitializedRef = false;
|
|
1184
1277
|
this.isFetchingRef = false;
|
|
1278
|
+
logger.debug("EventService", `User changed [ID:${this.instanceId}]`, {
|
|
1279
|
+
previousUserId,
|
|
1280
|
+
newUserId,
|
|
1281
|
+
willInitialize: newUserId !== null
|
|
1282
|
+
});
|
|
1185
1283
|
}
|
|
1186
1284
|
this.supabaseClient = supabaseClient;
|
|
1187
1285
|
this.user = user;
|
|
@@ -1189,15 +1287,31 @@ var EventService = class extends BaseService {
|
|
|
1189
1287
|
this.appName = appName;
|
|
1190
1288
|
this.selectedOrganisation = selectedOrganisation;
|
|
1191
1289
|
this.setSelectedEventId = setSelectedEventId;
|
|
1192
|
-
if (previousAppName !== appName) {
|
|
1193
|
-
this.appConfig = null;
|
|
1194
|
-
}
|
|
1195
1290
|
if (user?.id) {
|
|
1196
1291
|
try {
|
|
1197
|
-
|
|
1292
|
+
const { isRBACInitialized: isRBACInitialized2, isSuperAdmin: checkSuperAdmin, setupRBAC: setupRBAC2 } = await import("./api-IAGWF3ZG.js");
|
|
1293
|
+
if (!isRBACInitialized2() && this.supabaseClient) {
|
|
1294
|
+
setupRBAC2(this.supabaseClient);
|
|
1295
|
+
}
|
|
1296
|
+
if (isRBACInitialized2()) {
|
|
1297
|
+
this.isSuperAdmin = await checkSuperAdmin(user.id);
|
|
1298
|
+
logger.debug("EventService", "Super admin status updated in updateDependencies", {
|
|
1299
|
+
userId: user.id,
|
|
1300
|
+
isSuperAdmin: this.isSuperAdmin
|
|
1301
|
+
});
|
|
1302
|
+
} else {
|
|
1303
|
+
logger.warn("EventService", "RBAC not initialized in updateDependencies, keeping existing super admin status", {
|
|
1304
|
+
userId: user.id,
|
|
1305
|
+
existingIsSuperAdmin: this.isSuperAdmin,
|
|
1306
|
+
note: "RBAC should be initialized by UnifiedAuthProvider. This may indicate EventService is being used outside the provider."
|
|
1307
|
+
});
|
|
1308
|
+
}
|
|
1198
1309
|
} catch (error) {
|
|
1199
|
-
logger.warn("EventService", "Failed to check super admin status", {
|
|
1200
|
-
|
|
1310
|
+
logger.warn("EventService", "Failed to check super admin status in updateDependencies", {
|
|
1311
|
+
error,
|
|
1312
|
+
userId: user.id,
|
|
1313
|
+
existingIsSuperAdmin: this.isSuperAdmin
|
|
1314
|
+
});
|
|
1201
1315
|
}
|
|
1202
1316
|
} else {
|
|
1203
1317
|
this.isSuperAdmin = false;
|
|
@@ -1206,12 +1320,17 @@ var EventService = class extends BaseService {
|
|
|
1206
1320
|
this.resetInitialization();
|
|
1207
1321
|
this.isInitializedRef = false;
|
|
1208
1322
|
this.isFetchingRef = false;
|
|
1323
|
+
const shouldClearEvents = !this.isSuperAdmin;
|
|
1209
1324
|
if (previousOrgId !== null && newOrgId !== null && previousOrgId !== newOrgId) {
|
|
1210
|
-
|
|
1211
|
-
|
|
1325
|
+
if (shouldClearEvents) {
|
|
1326
|
+
this.events = [];
|
|
1327
|
+
this.setSelectedEvent(null);
|
|
1328
|
+
}
|
|
1212
1329
|
} else if (previousOrgId !== null && newOrgId === null) {
|
|
1213
|
-
|
|
1214
|
-
|
|
1330
|
+
if (shouldClearEvents) {
|
|
1331
|
+
this.events = [];
|
|
1332
|
+
this.setSelectedEvent(null);
|
|
1333
|
+
}
|
|
1215
1334
|
}
|
|
1216
1335
|
}
|
|
1217
1336
|
this.notify();
|
|
@@ -1335,9 +1454,11 @@ var EventService = class extends BaseService {
|
|
|
1335
1454
|
}
|
|
1336
1455
|
async doInitialize() {
|
|
1337
1456
|
if (this.isInitializedRef) {
|
|
1457
|
+
logger.debug("EventService", "Skipping initialization - already initialized");
|
|
1338
1458
|
return;
|
|
1339
1459
|
}
|
|
1340
1460
|
if (this.isFetchingRef) {
|
|
1461
|
+
logger.debug("EventService", "Skipping initialization - already fetching");
|
|
1341
1462
|
return;
|
|
1342
1463
|
}
|
|
1343
1464
|
try {
|
|
@@ -1348,10 +1469,22 @@ var EventService = class extends BaseService {
|
|
|
1348
1469
|
logger.warn("EventService", "Failed to clean up old storage keys:", error);
|
|
1349
1470
|
}
|
|
1350
1471
|
if (!this.user) {
|
|
1472
|
+
logger.debug("EventService", "Skipping initialization - no user");
|
|
1351
1473
|
return;
|
|
1352
1474
|
}
|
|
1475
|
+
logger.debug("EventService", "Initializing", {
|
|
1476
|
+
userId: this.user.id,
|
|
1477
|
+
appName: this.appName,
|
|
1478
|
+
hasSelectedOrganisation: !!this.selectedOrganisation,
|
|
1479
|
+
hasSupabaseClient: !!this.supabaseClient,
|
|
1480
|
+
hasSession: !!this.session
|
|
1481
|
+
});
|
|
1353
1482
|
await this.fetchEvents(false);
|
|
1354
1483
|
this.isInitializedRef = true;
|
|
1484
|
+
logger.debug("EventService", "Initialization complete", {
|
|
1485
|
+
eventsCount: this.events.length,
|
|
1486
|
+
hasError: !!this.error
|
|
1487
|
+
});
|
|
1355
1488
|
}
|
|
1356
1489
|
doCleanup() {
|
|
1357
1490
|
}
|
|
@@ -1368,55 +1501,91 @@ var EventService = class extends BaseService {
|
|
|
1368
1501
|
this.isFetchingRef = true;
|
|
1369
1502
|
let isMounted = true;
|
|
1370
1503
|
try {
|
|
1371
|
-
if (!this.appConfig && this.appName) {
|
|
1372
|
-
try {
|
|
1373
|
-
this.appConfig = await getAppConfigByName(this.appName);
|
|
1374
|
-
} catch (configError) {
|
|
1375
|
-
logger.warn("EventService", "Failed to load app config, defaulting to event-required", {
|
|
1376
|
-
error: configError
|
|
1377
|
-
});
|
|
1378
|
-
this.appConfig = { requires_event: true };
|
|
1379
|
-
}
|
|
1380
|
-
}
|
|
1381
1504
|
let organisationIdForRpc = null;
|
|
1382
|
-
let userIsSuperAdmin =
|
|
1505
|
+
let userIsSuperAdmin = this.isSuperAdmin;
|
|
1383
1506
|
try {
|
|
1384
|
-
|
|
1507
|
+
const { isRBACInitialized: isRBACInitialized2, isSuperAdmin: checkSuperAdmin, setupRBAC: setupRBAC2 } = await import("./api-IAGWF3ZG.js");
|
|
1508
|
+
if (!isRBACInitialized2() && this.supabaseClient) {
|
|
1509
|
+
setupRBAC2(this.supabaseClient);
|
|
1510
|
+
}
|
|
1511
|
+
if (isRBACInitialized2()) {
|
|
1512
|
+
userIsSuperAdmin = await checkSuperAdmin(this.user.id);
|
|
1513
|
+
this.isSuperAdmin = userIsSuperAdmin;
|
|
1514
|
+
logger.debug("EventService", "Super admin check completed", {
|
|
1515
|
+
userId: this.user.id,
|
|
1516
|
+
isSuperAdmin: userIsSuperAdmin
|
|
1517
|
+
});
|
|
1518
|
+
} else {
|
|
1519
|
+
if (this.isSuperAdmin) {
|
|
1520
|
+
userIsSuperAdmin = true;
|
|
1521
|
+
logger.warn("EventService", "RBAC not initialized, using cached super admin status", {
|
|
1522
|
+
userId: this.user.id,
|
|
1523
|
+
cachedIsSuperAdmin: this.isSuperAdmin,
|
|
1524
|
+
note: "RBAC should be initialized by UnifiedAuthProvider. This may indicate EventService is being used outside the provider."
|
|
1525
|
+
});
|
|
1526
|
+
} else {
|
|
1527
|
+
logger.warn("EventService", "RBAC not initialized, using cached non-super-admin status", {
|
|
1528
|
+
userId: this.user.id,
|
|
1529
|
+
cachedIsSuperAdmin: this.isSuperAdmin,
|
|
1530
|
+
note: "RBAC should be initialized by UnifiedAuthProvider. This may indicate EventService is being used outside the provider."
|
|
1531
|
+
});
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1385
1534
|
if (userIsSuperAdmin) {
|
|
1386
1535
|
organisationIdForRpc = null;
|
|
1387
1536
|
} else {
|
|
1388
1537
|
if (this.selectedEvent) {
|
|
1389
1538
|
organisationIdForRpc = this.selectedEvent.organisation_id;
|
|
1390
|
-
} else if (this.appConfig?.requires_event === true) {
|
|
1391
|
-
organisationIdForRpc = null;
|
|
1392
1539
|
} else if (this.selectedOrganisation) {
|
|
1393
1540
|
organisationIdForRpc = this.selectedOrganisation.id;
|
|
1394
1541
|
} else {
|
|
1395
|
-
logger.
|
|
1542
|
+
logger.debug("EventService", "No organisation context available, fetching all accessible events", {
|
|
1396
1543
|
hasSelectedEvent: !!this.selectedEvent,
|
|
1397
|
-
hasSelectedOrganisation: !!this.selectedOrganisation
|
|
1398
|
-
appRequiresEvent: this.appConfig?.requires_event
|
|
1544
|
+
hasSelectedOrganisation: !!this.selectedOrganisation
|
|
1399
1545
|
});
|
|
1400
1546
|
organisationIdForRpc = null;
|
|
1401
1547
|
}
|
|
1402
1548
|
}
|
|
1403
1549
|
} catch (superAdminCheckError) {
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
});
|
|
1407
|
-
if (this.selectedEvent) {
|
|
1408
|
-
organisationIdForRpc = this.selectedEvent.organisation_id;
|
|
1409
|
-
} else if (this.appConfig?.requires_event === true) {
|
|
1550
|
+
if (this.isSuperAdmin) {
|
|
1551
|
+
userIsSuperAdmin = true;
|
|
1410
1552
|
organisationIdForRpc = null;
|
|
1411
|
-
|
|
1412
|
-
|
|
1553
|
+
logger.warn("EventService", "Super admin check failed, using cached super admin status", {
|
|
1554
|
+
error: superAdminCheckError,
|
|
1555
|
+
cachedIsSuperAdmin: this.isSuperAdmin
|
|
1556
|
+
});
|
|
1557
|
+
} else {
|
|
1558
|
+
logger.warn("EventService", "Failed to check super admin status, using organisation-scoped query", {
|
|
1559
|
+
error: superAdminCheckError,
|
|
1560
|
+
cachedIsSuperAdmin: this.isSuperAdmin
|
|
1561
|
+
});
|
|
1562
|
+
if (this.selectedEvent) {
|
|
1563
|
+
organisationIdForRpc = this.selectedEvent.organisation_id;
|
|
1564
|
+
} else if (this.selectedOrganisation) {
|
|
1565
|
+
organisationIdForRpc = this.selectedOrganisation.id;
|
|
1566
|
+
} else {
|
|
1567
|
+
organisationIdForRpc = null;
|
|
1568
|
+
}
|
|
1413
1569
|
}
|
|
1414
1570
|
}
|
|
1571
|
+
logger.debug("EventService", "Fetching events", {
|
|
1572
|
+
userId: this.user.id,
|
|
1573
|
+
organisationIdForRpc,
|
|
1574
|
+
appName: this.appName,
|
|
1575
|
+
hasSelectedEvent: !!this.selectedEvent,
|
|
1576
|
+
hasSelectedOrganisation: !!this.selectedOrganisation,
|
|
1577
|
+
isSuperAdmin: userIsSuperAdmin
|
|
1578
|
+
});
|
|
1415
1579
|
let { data, error: rpcError } = await this.supabaseClient.rpc("data_user_events_get", {
|
|
1416
1580
|
p_user_id: this.user.id,
|
|
1417
1581
|
p_organisation_id: organisationIdForRpc,
|
|
1418
1582
|
p_app_name: this.appName
|
|
1419
1583
|
});
|
|
1584
|
+
logger.debug("EventService", "RPC response", {
|
|
1585
|
+
dataLength: data?.length || 0,
|
|
1586
|
+
hasError: !!rpcError,
|
|
1587
|
+
error: rpcError
|
|
1588
|
+
});
|
|
1420
1589
|
if (rpcError) {
|
|
1421
1590
|
logger.error("EventService", "RPC error fetching events:", rpcError);
|
|
1422
1591
|
throw new Error(rpcError.message || "Failed to fetch events");
|
|
@@ -1439,7 +1608,15 @@ var EventService = class extends BaseService {
|
|
|
1439
1608
|
created_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1440
1609
|
updated_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
1441
1610
|
}));
|
|
1442
|
-
|
|
1611
|
+
const sortedEvents = [...transformedEvents].sort((a, b) => {
|
|
1612
|
+
if (a.event_date && b.event_date) {
|
|
1613
|
+
return new Date(b.event_date).getTime() - new Date(a.event_date).getTime();
|
|
1614
|
+
}
|
|
1615
|
+
if (a.event_date && !b.event_date) return -1;
|
|
1616
|
+
if (!a.event_date && b.event_date) return 1;
|
|
1617
|
+
return 0;
|
|
1618
|
+
});
|
|
1619
|
+
this.events = sortedEvents;
|
|
1443
1620
|
this.error = null;
|
|
1444
1621
|
this.hasAutoSelectedRef = false;
|
|
1445
1622
|
if (!skipLoadPersisted) {
|
|
@@ -1514,6 +1691,8 @@ var EventService = class extends BaseService {
|
|
|
1514
1691
|
return null;
|
|
1515
1692
|
}
|
|
1516
1693
|
};
|
|
1694
|
+
_EventService.instanceCount = 0;
|
|
1695
|
+
var EventService = _EventService;
|
|
1517
1696
|
|
|
1518
1697
|
// src/providers/services/EventServiceProvider.tsx
|
|
1519
1698
|
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
@@ -1527,27 +1706,52 @@ function EventServiceProvider({
|
|
|
1527
1706
|
selectedOrganisation,
|
|
1528
1707
|
setSelectedEventId
|
|
1529
1708
|
}) {
|
|
1530
|
-
const eventServiceRef =
|
|
1531
|
-
const initializingRef =
|
|
1709
|
+
const eventServiceRef = useRef3(null);
|
|
1710
|
+
const initializingRef = useRef3(false);
|
|
1532
1711
|
if (!eventServiceRef.current) {
|
|
1533
1712
|
eventServiceRef.current = new EventService(supabaseClient, user, session, appName, selectedOrganisation, setSelectedEventId);
|
|
1534
1713
|
}
|
|
1535
1714
|
const eventService = eventServiceRef.current;
|
|
1536
1715
|
useEffect3(() => {
|
|
1537
1716
|
let isMounted = true;
|
|
1717
|
+
logger.debug("EventServiceProvider", "useEffect triggered", {
|
|
1718
|
+
hasUser: !!user,
|
|
1719
|
+
userId: user?.id,
|
|
1720
|
+
hasSession: !!session,
|
|
1721
|
+
appName,
|
|
1722
|
+
isInitializing: initializingRef.current
|
|
1723
|
+
});
|
|
1538
1724
|
if (initializingRef.current) {
|
|
1725
|
+
logger.debug("EventServiceProvider", "Skipping - already initializing");
|
|
1539
1726
|
return;
|
|
1540
1727
|
}
|
|
1541
1728
|
const updateAndInitialize = async () => {
|
|
1542
1729
|
initializingRef.current = true;
|
|
1543
1730
|
try {
|
|
1731
|
+
logger.debug("EventServiceProvider", "Updating dependencies and initializing", {
|
|
1732
|
+
hasUser: !!user,
|
|
1733
|
+
userId: user?.id,
|
|
1734
|
+
hasSession: !!session,
|
|
1735
|
+
appName,
|
|
1736
|
+
hasSelectedOrganisation: !!selectedOrganisation
|
|
1737
|
+
});
|
|
1544
1738
|
await eventService.updateDependencies(supabaseClient, user, session, appName, selectedOrganisation, setSelectedEventId);
|
|
1545
1739
|
if (!isMounted) return;
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1740
|
+
if (user && session && supabaseClient && appName) {
|
|
1741
|
+
logger.debug("EventServiceProvider", "Initializing event service");
|
|
1742
|
+
await eventService.initialize().catch((error) => {
|
|
1743
|
+
if (isMounted) {
|
|
1744
|
+
logger.error("EventServiceProvider", "Failed to initialize event service:", error);
|
|
1745
|
+
}
|
|
1746
|
+
});
|
|
1747
|
+
} else {
|
|
1748
|
+
logger.debug("EventServiceProvider", "Skipping initialization - missing required dependencies", {
|
|
1749
|
+
hasUser: !!user,
|
|
1750
|
+
hasSession: !!session,
|
|
1751
|
+
hasSupabaseClient: !!supabaseClient,
|
|
1752
|
+
appName
|
|
1753
|
+
});
|
|
1754
|
+
}
|
|
1551
1755
|
} finally {
|
|
1552
1756
|
initializingRef.current = false;
|
|
1553
1757
|
}
|
|
@@ -1570,7 +1774,7 @@ function EventServiceProvider({
|
|
|
1570
1774
|
}
|
|
1571
1775
|
|
|
1572
1776
|
// src/providers/services/InactivityServiceProvider.tsx
|
|
1573
|
-
import { createContext as createContext4, useMemo as useMemo4, useEffect as useEffect4, useRef as
|
|
1777
|
+
import { createContext as createContext4, useMemo as useMemo4, useEffect as useEffect4, useRef as useRef4 } from "react";
|
|
1574
1778
|
|
|
1575
1779
|
// src/services/InactivityService.ts
|
|
1576
1780
|
var InactivityService = class extends BaseService {
|
|
@@ -1914,7 +2118,7 @@ function InactivityServiceProvider({
|
|
|
1914
2118
|
// REQUIRED: No default - must be explicitly provided
|
|
1915
2119
|
onIdleLogout
|
|
1916
2120
|
}) {
|
|
1917
|
-
const inactivityServiceRef =
|
|
2121
|
+
const inactivityServiceRef = useRef4(null);
|
|
1918
2122
|
if (!inactivityServiceRef.current) {
|
|
1919
2123
|
inactivityServiceRef.current = new InactivityService(supabaseClient, user, session, idleTimeoutMs, warnBeforeMs, onIdleLogout);
|
|
1920
2124
|
}
|
|
@@ -1943,14 +2147,14 @@ function InactivityServiceProvider({
|
|
|
1943
2147
|
}
|
|
1944
2148
|
|
|
1945
2149
|
// src/hooks/services/useAuthService.ts
|
|
1946
|
-
import { useContext, useReducer, useEffect as useEffect5, useRef as
|
|
2150
|
+
import { useContext, useReducer, useEffect as useEffect5, useRef as useRef5 } from "react";
|
|
1947
2151
|
function useAuthService() {
|
|
1948
2152
|
const context = useContext(AuthServiceContext);
|
|
1949
2153
|
if (!context) {
|
|
1950
2154
|
throw new Error("useAuthService must be used within AuthServiceProvider");
|
|
1951
2155
|
}
|
|
1952
2156
|
const [, forceUpdate] = useReducer((x) => x + 1, 0);
|
|
1953
|
-
const timeoutRef =
|
|
2157
|
+
const timeoutRef = useRef5(null);
|
|
1954
2158
|
useEffect5(() => {
|
|
1955
2159
|
const debouncedUpdate = () => {
|
|
1956
2160
|
if (timeoutRef.current) {
|
|
@@ -1973,14 +2177,14 @@ function useAuthService() {
|
|
|
1973
2177
|
}
|
|
1974
2178
|
|
|
1975
2179
|
// src/hooks/services/useOrganisationService.ts
|
|
1976
|
-
import { useContext as useContext2, useReducer as useReducer2, useEffect as useEffect6, useRef as
|
|
2180
|
+
import { useContext as useContext2, useReducer as useReducer2, useEffect as useEffect6, useRef as useRef6 } from "react";
|
|
1977
2181
|
function useOrganisationService() {
|
|
1978
2182
|
const context = useContext2(OrganisationServiceContext);
|
|
1979
2183
|
if (!context) {
|
|
1980
2184
|
throw new Error("useOrganisationService must be used within OrganisationServiceProvider");
|
|
1981
2185
|
}
|
|
1982
2186
|
const [, forceUpdate] = useReducer2((x) => x + 1, 0);
|
|
1983
|
-
const timeoutRef =
|
|
2187
|
+
const timeoutRef = useRef6(null);
|
|
1984
2188
|
useEffect6(() => {
|
|
1985
2189
|
const debouncedUpdate = () => {
|
|
1986
2190
|
if (timeoutRef.current) {
|
|
@@ -2026,14 +2230,14 @@ function useOrganisations() {
|
|
|
2026
2230
|
}
|
|
2027
2231
|
|
|
2028
2232
|
// src/hooks/services/useEventService.ts
|
|
2029
|
-
import { useContext as useContext3, useReducer as useReducer3, useEffect as useEffect7, useRef as
|
|
2233
|
+
import { useContext as useContext3, useReducer as useReducer3, useEffect as useEffect7, useRef as useRef7 } from "react";
|
|
2030
2234
|
function useEventService() {
|
|
2031
2235
|
const context = useContext3(EventServiceContext);
|
|
2032
2236
|
if (!context) {
|
|
2033
2237
|
throw new Error("useEventService must be used within EventServiceProvider");
|
|
2034
2238
|
}
|
|
2035
2239
|
const [, forceUpdate] = useReducer3((x) => x + 1, 0);
|
|
2036
|
-
const timeoutRef =
|
|
2240
|
+
const timeoutRef = useRef7(null);
|
|
2037
2241
|
useEffect7(() => {
|
|
2038
2242
|
const debouncedUpdate = () => {
|
|
2039
2243
|
if (timeoutRef.current) {
|
|
@@ -2056,14 +2260,14 @@ function useEventService() {
|
|
|
2056
2260
|
}
|
|
2057
2261
|
|
|
2058
2262
|
// src/hooks/services/useInactivityService.ts
|
|
2059
|
-
import { useContext as useContext4, useReducer as useReducer4, useEffect as useEffect8, useRef as
|
|
2263
|
+
import { useContext as useContext4, useReducer as useReducer4, useEffect as useEffect8, useRef as useRef8 } from "react";
|
|
2060
2264
|
function useInactivityService() {
|
|
2061
2265
|
const context = useContext4(InactivityServiceContext);
|
|
2062
2266
|
if (!context) {
|
|
2063
2267
|
throw new Error("useInactivityService must be used within InactivityServiceProvider");
|
|
2064
2268
|
}
|
|
2065
2269
|
const [, forceUpdate] = useReducer4((x) => x + 1, 0);
|
|
2066
|
-
const timeoutRef =
|
|
2270
|
+
const timeoutRef = useRef8(null);
|
|
2067
2271
|
useEffect8(() => {
|
|
2068
2272
|
const debouncedUpdate = () => {
|
|
2069
2273
|
if (timeoutRef.current) {
|
|
@@ -2138,7 +2342,6 @@ var useUnifiedAuth = () => {
|
|
|
2138
2342
|
function UnifiedAuthContextProvider({
|
|
2139
2343
|
children,
|
|
2140
2344
|
appName,
|
|
2141
|
-
appConfig: appConfigProp,
|
|
2142
2345
|
supabaseClient: supabaseClientProp,
|
|
2143
2346
|
...props
|
|
2144
2347
|
}) {
|
|
@@ -2158,13 +2361,6 @@ function UnifiedAuthContextProvider({
|
|
|
2158
2361
|
restorationComplete,
|
|
2159
2362
|
restorationError
|
|
2160
2363
|
}), [isRestoring, restorationComplete, restorationError]);
|
|
2161
|
-
const [appConfigState, setAppConfigState] = useState3(appConfigProp || null);
|
|
2162
|
-
const isResolvingAppConfigRef = useRef8(false);
|
|
2163
|
-
const resolvedAppConfigRef = useRef8(null);
|
|
2164
|
-
const appConfig = useMemo6(() => {
|
|
2165
|
-
if (!appConfigState) return null;
|
|
2166
|
-
return { requires_event: appConfigState.requires_event };
|
|
2167
|
-
}, [appConfigState?.requires_event]);
|
|
2168
2364
|
let eventService;
|
|
2169
2365
|
try {
|
|
2170
2366
|
eventService = useEventService();
|
|
@@ -2188,9 +2384,17 @@ function UnifiedAuthContextProvider({
|
|
|
2188
2384
|
const isAuth = !!(currentUser && currentSession);
|
|
2189
2385
|
const supabase = useMemo6(() => supabaseClientProp, [supabaseClientProp]);
|
|
2190
2386
|
const [appId, setAppId] = useState3(void 0);
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2387
|
+
useEffect10(() => {
|
|
2388
|
+
logger.debug("UnifiedAuthContextProvider", `Rendering [AuthService ID:${authService.getInstanceId?.() || "unknown"}]`, {
|
|
2389
|
+
hasUser: !!currentUser,
|
|
2390
|
+
userId: currentUser?.id,
|
|
2391
|
+
hasSession: !!currentSession,
|
|
2392
|
+
isAuth
|
|
2393
|
+
});
|
|
2394
|
+
}, [currentUser?.id, currentSession?.access_token, isAuth, authService]);
|
|
2395
|
+
const isResolvingAppIdRef = useRef9(false);
|
|
2396
|
+
const resolvedAppIdRef = useRef9(void 0);
|
|
2397
|
+
const resolvedUserIdRef = useRef9(void 0);
|
|
2194
2398
|
useEffect10(() => {
|
|
2195
2399
|
if (!isAuth) {
|
|
2196
2400
|
resolvedAppIdRef.current = void 0;
|
|
@@ -2210,9 +2414,9 @@ function UnifiedAuthContextProvider({
|
|
|
2210
2414
|
resolvedUserIdRef.current = currentUserId;
|
|
2211
2415
|
const userId = currentUserId;
|
|
2212
2416
|
const appNameValue = appName;
|
|
2213
|
-
import("./api-
|
|
2417
|
+
import("./api-IAGWF3ZG.js").then(async ({ resolveAppContext, setupRBAC: setupRBAC2 }) => {
|
|
2214
2418
|
try {
|
|
2215
|
-
|
|
2419
|
+
setupRBAC2(supabase);
|
|
2216
2420
|
const result = await resolveAppContext({
|
|
2217
2421
|
userId,
|
|
2218
2422
|
appName: appNameValue
|
|
@@ -2240,59 +2444,8 @@ function UnifiedAuthContextProvider({
|
|
|
2240
2444
|
});
|
|
2241
2445
|
}
|
|
2242
2446
|
}, [isAuth, currentUser?.id, supabase, appName]);
|
|
2243
|
-
useEffect10(() => {
|
|
2244
|
-
if (appConfigProp !== void 0) {
|
|
2245
|
-
setAppConfigState(appConfigProp);
|
|
2246
|
-
resolvedAppConfigRef.current = appConfigProp;
|
|
2247
|
-
return;
|
|
2248
|
-
}
|
|
2249
|
-
if (resolvedAppConfigRef.current !== null || isResolvingAppConfigRef.current) {
|
|
2250
|
-
return;
|
|
2251
|
-
}
|
|
2252
|
-
if (!supabase || !appName) {
|
|
2253
|
-
return;
|
|
2254
|
-
}
|
|
2255
|
-
isResolvingAppConfigRef.current = true;
|
|
2256
|
-
import("./api-MVVQZLJI.js").then(async ({ getAppConfigByName: getAppConfigByName2 }) => {
|
|
2257
|
-
try {
|
|
2258
|
-
const config = await getAppConfigByName2(appName);
|
|
2259
|
-
const resolvedConfig = config || { requires_event: false };
|
|
2260
|
-
if (resolvedAppConfigRef.current?.requires_event !== resolvedConfig.requires_event) {
|
|
2261
|
-
resolvedAppConfigRef.current = resolvedConfig;
|
|
2262
|
-
setAppConfigState(resolvedConfig);
|
|
2263
|
-
}
|
|
2264
|
-
if (import.meta.env.DEV && appName === "MINT") {
|
|
2265
|
-
logger.debug("UnifiedAuthProvider", "App config loaded", {
|
|
2266
|
-
appName,
|
|
2267
|
-
config: resolvedConfig,
|
|
2268
|
-
requiresEvent: resolvedConfig.requires_event
|
|
2269
|
-
});
|
|
2270
|
-
}
|
|
2271
|
-
} catch (error) {
|
|
2272
|
-
logger.warn("UnifiedAuthProvider", "Failed to load app config, defaulting to organisation-based", {
|
|
2273
|
-
error: error instanceof Error ? error.message : String(error),
|
|
2274
|
-
appName
|
|
2275
|
-
});
|
|
2276
|
-
if (resolvedAppConfigRef.current?.requires_event !== false) {
|
|
2277
|
-
const defaultConfig = { requires_event: false };
|
|
2278
|
-
resolvedAppConfigRef.current = defaultConfig;
|
|
2279
|
-
setAppConfigState(defaultConfig);
|
|
2280
|
-
}
|
|
2281
|
-
} finally {
|
|
2282
|
-
isResolvingAppConfigRef.current = false;
|
|
2283
|
-
}
|
|
2284
|
-
}).catch((importError) => {
|
|
2285
|
-
logger.error("UnifiedAuthProvider", "Failed to import RBAC API for app config", importError);
|
|
2286
|
-
isResolvingAppConfigRef.current = false;
|
|
2287
|
-
if (resolvedAppConfigRef.current?.requires_event !== false) {
|
|
2288
|
-
const defaultConfig = { requires_event: false };
|
|
2289
|
-
resolvedAppConfigRef.current = defaultConfig;
|
|
2290
|
-
setAppConfigState(defaultConfig);
|
|
2291
|
-
}
|
|
2292
|
-
});
|
|
2293
|
-
}, [supabase, appName, appConfigProp]);
|
|
2294
2447
|
const [, forceUpdate] = useReducer5((x) => x + 1, 0);
|
|
2295
|
-
const forceUpdateTimeoutRef =
|
|
2448
|
+
const forceUpdateTimeoutRef = useRef9(null);
|
|
2296
2449
|
const debouncedForceUpdate = useCallback(() => {
|
|
2297
2450
|
if (forceUpdateTimeoutRef.current) {
|
|
2298
2451
|
clearTimeout(forceUpdateTimeoutRef.current);
|
|
@@ -2302,10 +2455,10 @@ function UnifiedAuthContextProvider({
|
|
|
2302
2455
|
forceUpdateTimeoutRef.current = null;
|
|
2303
2456
|
}, 100);
|
|
2304
2457
|
}, [forceUpdate]);
|
|
2305
|
-
const authServiceRef =
|
|
2306
|
-
const organisationServiceRef =
|
|
2307
|
-
const eventServiceRef =
|
|
2308
|
-
const inactivityServiceRef =
|
|
2458
|
+
const authServiceRef = useRef9(authService);
|
|
2459
|
+
const organisationServiceRef = useRef9(organisationService);
|
|
2460
|
+
const eventServiceRef = useRef9(eventService);
|
|
2461
|
+
const inactivityServiceRef = useRef9(inactivityService);
|
|
2309
2462
|
useEffect10(() => {
|
|
2310
2463
|
authServiceRef.current = authService;
|
|
2311
2464
|
organisationServiceRef.current = organisationService;
|
|
@@ -2336,20 +2489,7 @@ function UnifiedAuthContextProvider({
|
|
|
2336
2489
|
const authError = authService.getError();
|
|
2337
2490
|
const rawSelectedOrganisation = organisationService.getSelectedOrganisation();
|
|
2338
2491
|
const organisationError = organisationService.getError();
|
|
2339
|
-
const selectedOrganisation =
|
|
2340
|
-
useEffect10(() => {
|
|
2341
|
-
if (import.meta.env.DEV && appName === "MINT") {
|
|
2342
|
-
logger.debug("UnifiedAuthProvider", "Organisation state check", {
|
|
2343
|
-
rawSelectedOrganisation: rawSelectedOrganisation?.id || null,
|
|
2344
|
-
rawSelectedOrganisationType: typeof rawSelectedOrganisation,
|
|
2345
|
-
appConfig,
|
|
2346
|
-
appConfigRequiresEvent: appConfig?.requires_event,
|
|
2347
|
-
selectedOrganisation: selectedOrganisation?.id || null,
|
|
2348
|
-
selectedOrganisationId: selectedOrganisation?.id || null,
|
|
2349
|
-
checkResult: appConfig?.requires_event === true
|
|
2350
|
-
});
|
|
2351
|
-
}
|
|
2352
|
-
}, [appName, rawSelectedOrganisation?.id, appConfig?.requires_event, selectedOrganisation?.id]);
|
|
2492
|
+
const selectedOrganisation = rawSelectedOrganisation;
|
|
2353
2493
|
const hasValidOrganisationContext = organisationService.hasValidOrganisationContext();
|
|
2354
2494
|
const isContextReady = organisationService.isContextReady();
|
|
2355
2495
|
const rawEvents = eventService.getEvents();
|
|
@@ -2418,7 +2558,7 @@ function UnifiedAuthContextProvider({
|
|
|
2418
2558
|
const handleIdleLogout = () => inactivityService.handleIdleLogout();
|
|
2419
2559
|
const handleStaySignedIn = () => inactivityService.handleStaySignedIn();
|
|
2420
2560
|
const handleSignOutNow = () => inactivityService.handleSignOutNow();
|
|
2421
|
-
const prevStateRef =
|
|
2561
|
+
const prevStateRef = useRef9(null);
|
|
2422
2562
|
const isDev = import.meta.env.DEV || import.meta.env.MODE === "development";
|
|
2423
2563
|
if (isDev) {
|
|
2424
2564
|
const currentState = {
|
|
@@ -2491,7 +2631,6 @@ function UnifiedAuthContextProvider({
|
|
|
2491
2631
|
appName,
|
|
2492
2632
|
appId,
|
|
2493
2633
|
// Resolved immediately on login
|
|
2494
|
-
appConfig,
|
|
2495
2634
|
isLoading: totalLoading,
|
|
2496
2635
|
hasErrors,
|
|
2497
2636
|
sessionRestoration,
|
|
@@ -2524,7 +2663,6 @@ function UnifiedAuthContextProvider({
|
|
|
2524
2663
|
hasErrors,
|
|
2525
2664
|
appName,
|
|
2526
2665
|
appId,
|
|
2527
|
-
appConfig,
|
|
2528
2666
|
sessionRestoration,
|
|
2529
2667
|
sessionRestorationTimedOut,
|
|
2530
2668
|
sessionRestorationTimeoutMs,
|
|
@@ -2558,13 +2696,19 @@ function EventServiceProviderWrapper({
|
|
|
2558
2696
|
supabaseClient,
|
|
2559
2697
|
user,
|
|
2560
2698
|
session,
|
|
2561
|
-
appName
|
|
2562
|
-
appConfig
|
|
2699
|
+
appName
|
|
2563
2700
|
}) {
|
|
2564
|
-
const { selectedOrganisation
|
|
2565
|
-
const selectedOrganisation = appConfig !== null && appConfig?.requires_event === true && !rawSelectedOrganisation ? null : rawSelectedOrganisation;
|
|
2701
|
+
const { selectedOrganisation } = useOrganisations();
|
|
2566
2702
|
const setSelectedEventId = useCallback(() => {
|
|
2567
2703
|
}, []);
|
|
2704
|
+
useEffect10(() => {
|
|
2705
|
+
logger.debug("EventServiceProviderWrapper", "Rendering with props", {
|
|
2706
|
+
hasUser: !!user,
|
|
2707
|
+
userId: user?.id,
|
|
2708
|
+
hasSession: !!session,
|
|
2709
|
+
selectedOrganisationId: selectedOrganisation?.id
|
|
2710
|
+
});
|
|
2711
|
+
}, [user?.id, session?.access_token, selectedOrganisation?.id]);
|
|
2568
2712
|
return /* @__PURE__ */ jsx5(
|
|
2569
2713
|
EventServiceProvider,
|
|
2570
2714
|
{
|
|
@@ -2582,7 +2726,6 @@ function ServiceAwareProviders({
|
|
|
2582
2726
|
children,
|
|
2583
2727
|
supabaseClient,
|
|
2584
2728
|
appName,
|
|
2585
|
-
appConfig,
|
|
2586
2729
|
persistState,
|
|
2587
2730
|
enablePersistence,
|
|
2588
2731
|
requireOrganisationContext,
|
|
@@ -2593,26 +2736,51 @@ function ServiceAwareProviders({
|
|
|
2593
2736
|
dangerouslyDisableInactivity
|
|
2594
2737
|
}) {
|
|
2595
2738
|
const authService = useAuthService();
|
|
2739
|
+
const [userState, setUserState] = useState3(() => authService.getUser());
|
|
2740
|
+
const [sessionState, setSessionState] = useState3(() => authService.getSession());
|
|
2741
|
+
useEffect10(() => {
|
|
2742
|
+
const unsubscribe = authService.subscribe(() => {
|
|
2743
|
+
const newUser = authService.getUser();
|
|
2744
|
+
const newSession = authService.getSession();
|
|
2745
|
+
logger.debug("ServiceAwareProviders", "Auth service notified, updating state", {
|
|
2746
|
+
hasUser: !!newUser,
|
|
2747
|
+
userId: newUser?.id,
|
|
2748
|
+
hasSession: !!newSession
|
|
2749
|
+
});
|
|
2750
|
+
setUserState(newUser);
|
|
2751
|
+
setSessionState(newSession);
|
|
2752
|
+
});
|
|
2753
|
+
return unsubscribe;
|
|
2754
|
+
}, [authService]);
|
|
2755
|
+
const user = userState;
|
|
2756
|
+
const session = sessionState;
|
|
2757
|
+
useEffect10(() => {
|
|
2758
|
+
logger.debug("ServiceAwareProviders", `User/session state [AuthService ID:${authService.getInstanceId?.() || "unknown"}]`, {
|
|
2759
|
+
hasUser: !!user,
|
|
2760
|
+
userId: user?.id,
|
|
2761
|
+
hasSession: !!session,
|
|
2762
|
+
sessionToken: session?.access_token ? "present" : "missing"
|
|
2763
|
+
});
|
|
2764
|
+
}, [user?.id, session?.access_token, authService]);
|
|
2596
2765
|
return /* @__PURE__ */ jsx5(
|
|
2597
2766
|
OrganisationServiceProvider,
|
|
2598
2767
|
{
|
|
2599
2768
|
supabaseClient,
|
|
2600
|
-
user
|
|
2601
|
-
session
|
|
2769
|
+
user,
|
|
2770
|
+
session,
|
|
2602
2771
|
children: /* @__PURE__ */ jsx5(
|
|
2603
2772
|
EventServiceProviderWrapper,
|
|
2604
2773
|
{
|
|
2605
2774
|
supabaseClient,
|
|
2606
|
-
user
|
|
2607
|
-
session
|
|
2775
|
+
user,
|
|
2776
|
+
session,
|
|
2608
2777
|
appName,
|
|
2609
|
-
appConfig,
|
|
2610
2778
|
children: /* @__PURE__ */ jsx5(
|
|
2611
2779
|
InactivityServiceProvider,
|
|
2612
2780
|
{
|
|
2613
2781
|
supabaseClient,
|
|
2614
|
-
user
|
|
2615
|
-
session
|
|
2782
|
+
user,
|
|
2783
|
+
session,
|
|
2616
2784
|
idleTimeoutMs,
|
|
2617
2785
|
warnBeforeMs,
|
|
2618
2786
|
onIdleLogout,
|
|
@@ -2620,7 +2788,6 @@ function ServiceAwareProviders({
|
|
|
2620
2788
|
UnifiedAuthContextProvider,
|
|
2621
2789
|
{
|
|
2622
2790
|
appName,
|
|
2623
|
-
appConfig,
|
|
2624
2791
|
supabaseClient,
|
|
2625
2792
|
persistState,
|
|
2626
2793
|
enablePersistence,
|
|
@@ -2644,8 +2811,6 @@ function UnifiedAuthProvider({
|
|
|
2644
2811
|
children,
|
|
2645
2812
|
supabaseClient,
|
|
2646
2813
|
appName,
|
|
2647
|
-
appConfig = { requires_event: true },
|
|
2648
|
-
// Default to requiring events
|
|
2649
2814
|
persistState = true,
|
|
2650
2815
|
enablePersistence,
|
|
2651
2816
|
requireOrganisationContext = true,
|
|
@@ -2658,7 +2823,7 @@ function UnifiedAuthProvider({
|
|
|
2658
2823
|
renderInactivityWarning,
|
|
2659
2824
|
dangerouslyDisableInactivity = false
|
|
2660
2825
|
}) {
|
|
2661
|
-
const clientRef =
|
|
2826
|
+
const clientRef = useRef9(supabaseClient);
|
|
2662
2827
|
useEffect10(() => {
|
|
2663
2828
|
if (clientRef.current !== supabaseClient) {
|
|
2664
2829
|
logger.warn("UnifiedAuthProvider", "Supabase client reference changed - this may indicate multiple client instances are being created", {
|
|
@@ -2667,14 +2832,23 @@ function UnifiedAuthProvider({
|
|
|
2667
2832
|
note: 'Ensure you create the Supabase client once and reuse it. Creating multiple clients can cause performance issues and the "Multiple GoTrueClient instances" warning.'
|
|
2668
2833
|
});
|
|
2669
2834
|
clientRef.current = supabaseClient;
|
|
2835
|
+
} else {
|
|
2836
|
+
logger.debug("UnifiedAuthProvider", "Supabase client reference is stable");
|
|
2670
2837
|
}
|
|
2671
2838
|
}, [supabaseClient]);
|
|
2839
|
+
if (supabaseClient && !isRBACInitialized()) {
|
|
2840
|
+
try {
|
|
2841
|
+
setupRBAC(supabaseClient);
|
|
2842
|
+
logger.debug("UnifiedAuthProvider", "RBAC initialized synchronously");
|
|
2843
|
+
} catch (err) {
|
|
2844
|
+
logger.error("UnifiedAuthProvider", "Failed to initialize RBAC", err);
|
|
2845
|
+
}
|
|
2846
|
+
}
|
|
2672
2847
|
return /* @__PURE__ */ jsx5(AuthServiceProvider, { supabaseClient, appName, children: /* @__PURE__ */ jsx5(
|
|
2673
2848
|
ServiceAwareProviders,
|
|
2674
2849
|
{
|
|
2675
2850
|
supabaseClient,
|
|
2676
2851
|
appName,
|
|
2677
|
-
appConfig,
|
|
2678
2852
|
persistState,
|
|
2679
2853
|
enablePersistence,
|
|
2680
2854
|
requireOrganisationContext,
|
|
@@ -2707,4 +2881,4 @@ export {
|
|
|
2707
2881
|
useUnifiedAuth,
|
|
2708
2882
|
UnifiedAuthProvider
|
|
2709
2883
|
};
|
|
2710
|
-
//# sourceMappingURL=chunk-
|
|
2884
|
+
//# sourceMappingURL=chunk-DWUBLJJM.js.map
|