@nibssplc/cams-sdk-react 0.0.1-beta.25 → 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,12 +1,12 @@
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 {
@@ -17,7 +17,7 @@ export interface UseCAMSMSALAuthReturn {
17
17
  isMFAPending: boolean;
18
18
  error: CAMSError | null;
19
19
  token: string | null;
20
- profile: Profile | null;
21
- account: AccountInfo | null;
20
+ idToken: string | null;
21
+ accessToken: string | null;
22
22
  }
23
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"];
@@ -16731,31 +16734,14 @@ function useCAMSMSALAuth(options) {
16731
16734
  .then(function (response) {
16732
16735
  var _a, _b;
16733
16736
  setToken(response.accessToken);
16734
- if (options.mfaUrl) {
16735
- setIsMFAPending(true);
16736
- (_a = options.onMFARequired) === null || _a === void 0 ? void 0 : _a.call(options, response.accessToken, account);
16737
- if (typeof window !== "undefined") {
16738
- window.location.href = options.mfaUrl;
16739
- }
16740
- }
16741
- else {
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);
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];
@@ -16842,8 +16827,8 @@ function useCAMSMSALAuth(options) {
16842
16827
  isMFAPending: isMFAPending,
16843
16828
  error: error,
16844
16829
  token: token,
16845
- profile: profile,
16846
- account: account,
16830
+ idToken: idToken,
16831
+ accessToken: accessToken,
16847
16832
  };
16848
16833
  }
16849
16834