@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.
@@ -0,0 +1,17 @@
1
+ import { Profile } from "@nibssplc/cams-sdk";
2
+ export interface UseCAMSPopupAuthOptions {
3
+ storageKey?: string;
4
+ targetOrigin?: string;
5
+ onAuthComplete?: (profile: Profile) => void;
6
+ onAuthError?: (error: any) => void;
7
+ }
8
+ export interface UseCAMSPopupAuthReturn {
9
+ completeAuth: (profile: Profile) => void;
10
+ errorAuth: (error: any) => void;
11
+ isPopup: boolean;
12
+ }
13
+ /**
14
+ * Hook for handling authentication in popup windows
15
+ * This should be used by the popup app to complete authentication
16
+ */
17
+ export declare function useCAMSPopupAuth(options?: UseCAMSPopupAuthOptions): UseCAMSPopupAuthReturn;
package/dist/index.cjs.js CHANGED
@@ -122,6 +122,10 @@ function useCAMSAuth(options) {
122
122
  // Only initialize on client side
123
123
  if (typeof window === "undefined")
124
124
  return;
125
+ // Initialize popup auth handler if in popup
126
+ if (camsSdk.isPopupWindow()) {
127
+ camsSdk.initializePopupAuth();
128
+ }
125
129
  (_a = sessionManagerRef.current) !== null && _a !== void 0 ? _a : (sessionManagerRef.current = new camsSdk.CAMSSessionManager(localStorage, options.storageKey || "CAMS-SDK", {
126
130
  onAuthSuccess: function (res) {
127
131
  var _a;
@@ -147,12 +151,14 @@ function useCAMSAuth(options) {
147
151
  (_a = options.onTokenExpired) === null || _a === void 0 ? void 0 : _a.call(options);
148
152
  },
149
153
  }));
150
- // Check initial auth state
151
- var initialAuth = sessionManagerRef.current.isAuthenticated();
152
- setIsAuthenticated(initialAuth);
153
- if (initialAuth) {
154
- setToken((_b = sessionManagerRef.current.getAccessToken()) !== null && _b !== void 0 ? _b : "");
155
- sessionManagerRef.current.getProfile().then(setProfile);
154
+ // Check initial auth state (skip if in popup)
155
+ if (!camsSdk.isPopupWindow()) {
156
+ var initialAuth = sessionManagerRef.current.isAuthenticated();
157
+ setIsAuthenticated(initialAuth);
158
+ if (initialAuth) {
159
+ setToken((_b = sessionManagerRef.current.getAccessToken()) !== null && _b !== void 0 ? _b : "");
160
+ sessionManagerRef.current.getProfile().then(setProfile);
161
+ }
156
162
  }
157
163
  }, [options.storageKey]);
158
164
  var login = React__default.useCallback(function (config) { return __awaiter(_this, void 0, void 0, function () {
@@ -16970,6 +16976,56 @@ function useCAMSMSALAuth(options) {
16970
16976
  };
16971
16977
  }
16972
16978
 
16979
+ /**
16980
+ * Hook for handling authentication in popup windows
16981
+ * This should be used by the popup app to complete authentication
16982
+ */
16983
+ function useCAMSPopupAuth(options) {
16984
+ if (options === void 0) { options = {}; }
16985
+ var _a = options.storageKey, storageKey = _a === void 0 ? "CAMS-SDK" : _a, targetOrigin = options.targetOrigin, onAuthComplete = options.onAuthComplete, onAuthError = options.onAuthError;
16986
+ React__default.useEffect(function () {
16987
+ if (typeof window === "undefined" || !camsSdk.isPopupWindow())
16988
+ return;
16989
+ // Initialize popup auth handler
16990
+ camsSdk.initializePopupAuth(targetOrigin);
16991
+ // Set up global handlers for the popup app
16992
+ var globalHandlers = window.__CAMS_POPUP_AUTH__;
16993
+ if (globalHandlers) {
16994
+ var originalCompleteAuth_1 = globalHandlers.completeAuth;
16995
+ var originalErrorAuth_1 = globalHandlers.errorAuth;
16996
+ globalHandlers.completeAuth = function (profile) {
16997
+ onAuthComplete === null || onAuthComplete === void 0 ? void 0 : onAuthComplete(profile);
16998
+ originalCompleteAuth_1(profile);
16999
+ };
17000
+ globalHandlers.errorAuth = function (error) {
17001
+ onAuthError === null || onAuthError === void 0 ? void 0 : onAuthError(error);
17002
+ originalErrorAuth_1(error);
17003
+ };
17004
+ }
17005
+ }, [targetOrigin, onAuthComplete, onAuthError]);
17006
+ var completeAuth = React__default.useCallback(function (profile) {
17007
+ if (!camsSdk.isPopupWindow()) {
17008
+ console.warn("completeAuth called outside of popup window");
17009
+ return;
17010
+ }
17011
+ var sessionManager = new camsSdk.CAMSSessionManager(localStorage, storageKey);
17012
+ sessionManager.completePopupAuth(profile, targetOrigin);
17013
+ }, [storageKey, targetOrigin]);
17014
+ var errorAuth = React__default.useCallback(function (error) {
17015
+ if (!camsSdk.isPopupWindow()) {
17016
+ console.warn("errorAuth called outside of popup window");
17017
+ return;
17018
+ }
17019
+ var sessionManager = new camsSdk.CAMSSessionManager(localStorage, storageKey);
17020
+ sessionManager.errorPopupAuth(error, targetOrigin);
17021
+ }, [storageKey, targetOrigin]);
17022
+ return {
17023
+ completeAuth: completeAuth,
17024
+ errorAuth: errorAuth,
17025
+ isPopup: camsSdk.isPopupWindow(),
17026
+ };
17027
+ }
17028
+
16973
17029
  var jsxRuntime = {exports: {}};
16974
17030
 
16975
17031
  var reactJsxRuntime_production = {};
@@ -19340,6 +19396,7 @@ exports.useCAMSAuth = useCAMSAuth;
19340
19396
  exports.useCAMSContext = useCAMSContext;
19341
19397
  exports.useCAMSMSALAuth = useCAMSMSALAuth;
19342
19398
  exports.useCAMSMSALContext = useCAMSMSALContext;
19399
+ exports.useCAMSPopupAuth = useCAMSPopupAuth;
19343
19400
  Object.keys(camsSdk).forEach(function (k) {
19344
19401
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
19345
19402
  enumerable: true,