@nibssplc/cams-sdk-react 0.0.1-beta.55 → 0.0.1-beta.57

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/dist/index.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './hooks/useCAMSAuth';
2
2
  export * from './hooks/useCAMSMSALAuth';
3
+ export * from './hooks/useCAMSPopupAuth';
3
4
  export * from './components/ProtectedRoute';
4
5
  export { CAMSMSALProvider, useCAMSMSALContext } from './components/CAMSMSALProvider';
5
6
  export * from './components/ClientOnly';
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as React__default from 'react';
2
2
  import React__default__default, { useState, useRef, useEffect, useCallback, useMemo, useReducer, useContext, createContext } from 'react';
3
- import { CAMSSessionManager, CAMSError, CAMSErrorType, Logger as Logger$1, ProfileSchema, AuthFailureMessageSchema, ErrorMessageSchema } from '@nibssplc/cams-sdk';
3
+ import { isPopupWindow, initializePopupAuth, CAMSSessionManager, CAMSError, CAMSErrorType, Logger as Logger$1, ProfileSchema, AuthFailureMessageSchema, ErrorMessageSchema } from '@nibssplc/cams-sdk';
4
4
  export * from '@nibssplc/cams-sdk';
5
5
 
6
6
  /******************************************************************************
@@ -103,6 +103,10 @@ function useCAMSAuth(options) {
103
103
  // Only initialize on client side
104
104
  if (typeof window === "undefined")
105
105
  return;
106
+ // Initialize popup auth handler if in popup
107
+ if (isPopupWindow()) {
108
+ initializePopupAuth();
109
+ }
106
110
  (_a = sessionManagerRef.current) !== null && _a !== void 0 ? _a : (sessionManagerRef.current = new CAMSSessionManager(localStorage, options.storageKey || "CAMS-SDK", {
107
111
  onAuthSuccess: function (res) {
108
112
  var _a;
@@ -128,12 +132,14 @@ function useCAMSAuth(options) {
128
132
  (_a = options.onTokenExpired) === null || _a === void 0 ? void 0 : _a.call(options);
129
133
  },
130
134
  }));
131
- // Check initial auth state
132
- var initialAuth = sessionManagerRef.current.isAuthenticated();
133
- setIsAuthenticated(initialAuth);
134
- if (initialAuth) {
135
- setToken((_b = sessionManagerRef.current.getAccessToken()) !== null && _b !== void 0 ? _b : "");
136
- sessionManagerRef.current.getProfile().then(setProfile);
135
+ // Check initial auth state (skip if in popup)
136
+ if (!isPopupWindow()) {
137
+ var initialAuth = sessionManagerRef.current.isAuthenticated();
138
+ setIsAuthenticated(initialAuth);
139
+ if (initialAuth) {
140
+ setToken((_b = sessionManagerRef.current.getAccessToken()) !== null && _b !== void 0 ? _b : "");
141
+ sessionManagerRef.current.getProfile().then(setProfile);
142
+ }
137
143
  }
138
144
  }, [options.storageKey]);
139
145
  var login = useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
@@ -16951,6 +16957,56 @@ function useCAMSMSALAuth(options) {
16951
16957
  };
16952
16958
  }
16953
16959
 
16960
+ /**
16961
+ * Hook for handling authentication in popup windows
16962
+ * This should be used by the popup app to complete authentication
16963
+ */
16964
+ function useCAMSPopupAuth(options) {
16965
+ if (options === void 0) { options = {}; }
16966
+ var _a = options.storageKey, storageKey = _a === void 0 ? "CAMS-SDK" : _a, targetOrigin = options.targetOrigin, onAuthComplete = options.onAuthComplete, onAuthError = options.onAuthError;
16967
+ useEffect(function () {
16968
+ if (typeof window === "undefined" || !isPopupWindow())
16969
+ return;
16970
+ // Initialize popup auth handler
16971
+ initializePopupAuth(targetOrigin);
16972
+ // Set up global handlers for the popup app
16973
+ var globalHandlers = window.__CAMS_POPUP_AUTH__;
16974
+ if (globalHandlers) {
16975
+ var originalCompleteAuth_1 = globalHandlers.completeAuth;
16976
+ var originalErrorAuth_1 = globalHandlers.errorAuth;
16977
+ globalHandlers.completeAuth = function (profile) {
16978
+ onAuthComplete === null || onAuthComplete === void 0 ? void 0 : onAuthComplete(profile);
16979
+ originalCompleteAuth_1(profile);
16980
+ };
16981
+ globalHandlers.errorAuth = function (error) {
16982
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(error);
16983
+ originalErrorAuth_1(error);
16984
+ };
16985
+ }
16986
+ }, [targetOrigin, onAuthComplete, onAuthError]);
16987
+ var completeAuth = useCallback(function (profile) {
16988
+ if (!isPopupWindow()) {
16989
+ console.warn("completeAuth called outside of popup window");
16990
+ return;
16991
+ }
16992
+ var sessionManager = new CAMSSessionManager(localStorage, storageKey);
16993
+ sessionManager.completePopupAuth(profile, targetOrigin);
16994
+ }, [storageKey, targetOrigin]);
16995
+ var errorAuth = useCallback(function (error) {
16996
+ if (!isPopupWindow()) {
16997
+ console.warn("errorAuth called outside of popup window");
16998
+ return;
16999
+ }
17000
+ var sessionManager = new CAMSSessionManager(localStorage, storageKey);
17001
+ sessionManager.errorPopupAuth(error, targetOrigin);
17002
+ }, [storageKey, targetOrigin]);
17003
+ return {
17004
+ completeAuth: completeAuth,
17005
+ errorAuth: errorAuth,
17006
+ isPopup: isPopupWindow(),
17007
+ };
17008
+ }
17009
+
16954
17010
  var jsxRuntime = {exports: {}};
16955
17011
 
16956
17012
  var reactJsxRuntime_production = {};
@@ -19312,5 +19368,5 @@ function useCAMSContext() {
19312
19368
  // Backward compatibility exports
19313
19369
  var CAMSProvider = function (props) { return (jsxRuntimeExports.jsx(UnifiedCAMSProvider, __assign({}, props, { mode: "REGULAR" }))); };
19314
19370
 
19315
- export { CAMSMSALProvider, CAMSProvider, ClientOnly, ProtectedRoute, UnifiedCAMSProvider, useCAMSAuth, useCAMSContext, useCAMSMSALAuth, useCAMSMSALContext };
19371
+ export { CAMSMSALProvider, CAMSProvider, ClientOnly, ProtectedRoute, UnifiedCAMSProvider, useCAMSAuth, useCAMSContext, useCAMSMSALAuth, useCAMSMSALContext, useCAMSPopupAuth };
19316
19372
  //# sourceMappingURL=index.esm.js.map