@nibssplc/cams-sdk-react 0.0.1-beta.24 → 0.0.1-beta.26

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.
@@ -1,24 +1,23 @@
1
1
  import { AccountInfo } from "@azure/msal-browser";
2
- import { CAMSError, Profile } from "@nibssplc/cams-sdk";
2
+ import { CAMSError } from "@nibssplc/cams-sdk";
3
3
  export interface UseCAMSMSALAuthOptions {
4
4
  onAuthSuccess?: (token: string) => void;
5
5
  onAuthError?: (error: CAMSError) => void;
6
6
  onTokenExpired?: () => void;
7
7
  onMFARequired?: (msalToken: string, account: AccountInfo) => void;
8
8
  scopes?: string[];
9
- mfaUrl?: string;
9
+ mfaUrl: string;
10
10
  prompt?: string;
11
11
  }
12
12
  export interface UseCAMSMSALAuthReturn {
13
13
  login: () => Promise<void>;
14
14
  logout: () => Promise<void>;
15
- completeMFA: (mfaToken: string) => void;
16
15
  isAuthenticated: boolean;
17
16
  isLoading: boolean;
18
17
  isMFAPending: boolean;
19
18
  error: CAMSError | null;
20
19
  token: string | null;
21
- profile: Profile | null;
22
- account: AccountInfo | null;
20
+ idToken: string | null;
21
+ accessToken: string | null;
23
22
  }
24
23
  export declare function useCAMSMSALAuth(options?: UseCAMSMSALAuthOptions): UseCAMSMSALAuthReturn;
package/dist/index.cjs.js CHANGED
@@ -16709,13 +16709,16 @@ function useAccount(accountIdentifiers) {
16709
16709
 
16710
16710
  function useCAMSMSALAuth(options) {
16711
16711
  var _this = this;
16712
- if (options === void 0) { options = {}; }
16712
+ if (options === void 0) { options = {
16713
+ mfaUrl: "/auth/multi-factor",
16714
+ }; }
16713
16715
  var _a = useMsal(), instance = _a.instance, inProgress = _a.inProgress, accounts = _a.accounts;
16714
16716
  var account = useAccount(accounts[0] || {});
16715
16717
  var _b = React__default.useState(null), error = _b[0], setError = _b[1];
16716
16718
  var _c = React__default.useState(null), token = _c[0], setToken = _c[1];
16717
- var _d = React__default.useState(null), profile = _d[0], setProfile = _d[1];
16718
- var _e = React__default.useState(false), isMFAPending = _e[0], setIsMFAPending = _e[1];
16719
+ var _d = React__default.useState(null), idToken = _d[0], setIdToken = _d[1];
16720
+ var _e = React__default.useState(null), accessToken = _e[0], setAccessToken = _e[1];
16721
+ var _f = React__default.useState(false), isMFAPending = _f[0], setIsMFAPending = _f[1];
16719
16722
  var isLoading = inProgress !== InteractionStatus.None;
16720
16723
  var isAuthenticated = !!account && !!token && !isMFAPending;
16721
16724
  var scopes = options.scopes || ["openid", "profile", "email"];
@@ -16730,32 +16733,15 @@ function useCAMSMSALAuth(options) {
16730
16733
  })
16731
16734
  .then(function (response) {
16732
16735
  var _a, _b;
16733
- if (options.mfaUrl) {
16734
- setIsMFAPending(true);
16735
- (_a = options.onMFARequired) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken, account);
16736
- if (typeof window !== "undefined") {
16737
- window.location.href = options.mfaUrl;
16738
- }
16739
- }
16740
- else {
16741
- setToken(response.accessToken);
16742
- setProfile({
16743
- type: "AUTH_SUCCESS",
16744
- userProfile: {
16745
- name: account.name || "",
16746
- email: account.username || "",
16747
- isAuthenticated: true,
16748
- mfaIsEnabled: true,
16749
- message: "Authentication successful",
16750
- userType: "USER",
16751
- tokens: {
16752
- Nonce: "",
16753
- Bearer: response.accessToken,
16754
- },
16755
- },
16756
- });
16757
- (_b = options.onAuthSuccess) === null || _b === void 0 ? void 0 : _b.call(options, response.accessToken);
16736
+ setToken(response.accessToken);
16737
+ setAccessToken(response.accessToken);
16738
+ setIdToken(response.idToken);
16739
+ setIsMFAPending(true);
16740
+ (_a = options.onMFARequired) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken, account);
16741
+ if (typeof window !== "undefined") {
16742
+ window.location.href = options.mfaUrl;
16758
16743
  }
16744
+ (_b = options.onAuthSuccess) === null || _b === void 0 ? void 0 : _b.call(options, response.accessToken);
16759
16745
  })
16760
16746
  .catch(function (err) {
16761
16747
  var _a;
@@ -16821,7 +16807,6 @@ function useCAMSMSALAuth(options) {
16821
16807
  case 1:
16822
16808
  _a.sent();
16823
16809
  setToken(null);
16824
- setProfile(null);
16825
16810
  setError(null);
16826
16811
  setIsMFAPending(false);
16827
16812
  return [3 /*break*/, 3];
@@ -16834,40 +16819,16 @@ function useCAMSMSALAuth(options) {
16834
16819
  }
16835
16820
  });
16836
16821
  }); }, [instance]);
16837
- var completeMFA = React__default.useCallback(function (mfaToken) {
16838
- var _a;
16839
- setToken(mfaToken);
16840
- setIsMFAPending(false);
16841
- if (account) {
16842
- setProfile({
16843
- type: "AUTH_SUCCESS",
16844
- userProfile: {
16845
- name: account.name || "",
16846
- email: account.username || "",
16847
- isAuthenticated: true,
16848
- mfaIsEnabled: true,
16849
- message: "Authentication successful",
16850
- userType: "USER",
16851
- tokens: {
16852
- Nonce: "",
16853
- Bearer: token !== null && token !== void 0 ? token : "",
16854
- },
16855
- },
16856
- });
16857
- }
16858
- (_a = options.onAuthSuccess) === null || _a === void 0 ? void 0 : _a.call(options, mfaToken);
16859
- }, [account, options]);
16860
16822
  return {
16861
16823
  login: login,
16862
16824
  logout: logout,
16863
- completeMFA: completeMFA,
16864
16825
  isAuthenticated: isAuthenticated,
16865
16826
  isLoading: isLoading,
16866
16827
  isMFAPending: isMFAPending,
16867
16828
  error: error,
16868
16829
  token: token,
16869
- profile: profile,
16870
- account: account,
16830
+ idToken: idToken,
16831
+ accessToken: accessToken,
16871
16832
  };
16872
16833
  }
16873
16834