@azure/msal-react 2.0.0-alpha.1 → 2.0.0-alpha.2

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.
Files changed (38) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +144 -144
  3. package/dist/MsalContext.d.ts +10 -10
  4. package/dist/MsalContext.js +16 -16
  5. package/dist/MsalProvider.d.ts +9 -9
  6. package/dist/MsalProvider.js +131 -131
  7. package/dist/components/AuthenticatedTemplate.d.ts +8 -8
  8. package/dist/components/AuthenticatedTemplate.js +23 -23
  9. package/dist/components/MsalAuthenticationTemplate.d.ts +16 -16
  10. package/dist/components/MsalAuthenticationTemplate.js +33 -33
  11. package/dist/components/UnauthenticatedTemplate.d.ts +8 -8
  12. package/dist/components/UnauthenticatedTemplate.js +25 -25
  13. package/dist/components/withMsal.d.ts +11 -11
  14. package/dist/components/withMsal.js +17 -17
  15. package/dist/error/ReactAuthError.d.ts +16 -16
  16. package/dist/error/ReactAuthError.js +27 -27
  17. package/dist/hooks/useAccount.d.ts +7 -7
  18. package/dist/hooks/useAccount.js +33 -33
  19. package/dist/hooks/useIsAuthenticated.d.ts +6 -6
  20. package/dist/hooks/useIsAuthenticated.js +30 -30
  21. package/dist/hooks/useMsal.d.ts +5 -5
  22. package/dist/hooks/useMsal.js +8 -8
  23. package/dist/hooks/useMsalAuthentication.d.ts +18 -18
  24. package/dist/hooks/useMsalAuthentication.js +184 -184
  25. package/dist/index.d.ts +23 -23
  26. package/dist/index.js +1 -1
  27. package/dist/packageMetadata.d.ts +2 -2
  28. package/dist/packageMetadata.js +4 -4
  29. package/dist/types/AccountIdentifiers.d.ts +2 -2
  30. package/dist/utils/utilities.d.ts +17 -17
  31. package/dist/utils/utilities.js +60 -60
  32. package/package.json +65 -65
  33. package/dist/msal-react.cjs.development.js +0 -685
  34. package/dist/msal-react.cjs.development.js.map +0 -1
  35. package/dist/msal-react.cjs.production.min.js +0 -2
  36. package/dist/msal-react.cjs.production.min.js.map +0 -1
  37. package/dist/msal-react.esm.js +0 -667
  38. package/dist/msal-react.esm.js.map +0 -1
@@ -1,667 +0,0 @@
1
- import React__default, { createContext, useEffect, useMemo, useReducer, useContext, useState, useRef, useCallback } from 'react';
2
- import { stubbedPublicClientApplication, InteractionStatus, Logger, WrapperSKU, EventMessageUtils, AccountEntity, AuthError, InteractionType, InteractionRequiredAuthError, EventType, OIDC_DEFAULT_SCOPES } from '@azure/msal-browser';
3
-
4
- /*
5
- * Copyright (c) Microsoft Corporation. All rights reserved.
6
- * Licensed under the MIT License.
7
- */
8
- /*
9
- * Stubbed context implementation
10
- * Only used when there is no provider, which is an unsupported scenario
11
- */
12
-
13
- const defaultMsalContext = {
14
- instance: stubbedPublicClientApplication,
15
- inProgress: InteractionStatus.None,
16
- accounts: [],
17
- logger: /*#__PURE__*/new Logger({})
18
- };
19
- const MsalContext = /*#__PURE__*/createContext(defaultMsalContext);
20
- const MsalConsumer = MsalContext.Consumer;
21
-
22
- /*
23
- * Copyright (c) Microsoft Corporation. All rights reserved.
24
- * Licensed under the MIT License.
25
- */
26
- function getChildrenOrFunction(children, args) {
27
- if (typeof children === "function") {
28
- return children(args);
29
- }
30
-
31
- return children;
32
- }
33
- /**
34
- * Helper function to determine whether 2 arrays are equal
35
- * Used to avoid unnecessary state updates
36
- * @param arrayA
37
- * @param arrayB
38
- */
39
-
40
- function accountArraysAreEqual(arrayA, arrayB) {
41
- if (arrayA.length !== arrayB.length) {
42
- return false;
43
- }
44
-
45
- const comparisonArray = [...arrayB];
46
- return arrayA.every(elementA => {
47
- const elementB = comparisonArray.shift();
48
-
49
- if (!elementA || !elementB) {
50
- return false;
51
- }
52
-
53
- return elementA.homeAccountId === elementB.homeAccountId && elementA.localAccountId === elementB.localAccountId && elementA.username === elementB.username;
54
- });
55
- }
56
- function getAccountByIdentifiers(allAccounts, accountIdentifiers) {
57
- if (allAccounts.length > 0 && (accountIdentifiers.homeAccountId || accountIdentifiers.localAccountId || accountIdentifiers.username)) {
58
- const matchedAccounts = allAccounts.filter(accountObj => {
59
- if (accountIdentifiers.username && accountIdentifiers.username.toLowerCase() !== accountObj.username.toLowerCase()) {
60
- return false;
61
- }
62
-
63
- if (accountIdentifiers.homeAccountId && accountIdentifiers.homeAccountId.toLowerCase() !== accountObj.homeAccountId.toLowerCase()) {
64
- return false;
65
- }
66
-
67
- if (accountIdentifiers.localAccountId && accountIdentifiers.localAccountId.toLowerCase() !== accountObj.localAccountId.toLowerCase()) {
68
- return false;
69
- }
70
-
71
- return true;
72
- });
73
- return matchedAccounts[0] || null;
74
- } else {
75
- return null;
76
- }
77
- }
78
-
79
- /* eslint-disable header/header */
80
- const name = "@azure/msal-react";
81
- const version = "1.5.7";
82
-
83
- /*
84
- * Copyright (c) Microsoft Corporation. All rights reserved.
85
- * Licensed under the MIT License.
86
- */
87
- var MsalProviderActionType;
88
-
89
- (function (MsalProviderActionType) {
90
- MsalProviderActionType["UNBLOCK_INPROGRESS"] = "UNBLOCK_INPROGRESS";
91
- MsalProviderActionType["EVENT"] = "EVENT";
92
- })(MsalProviderActionType || (MsalProviderActionType = {}));
93
- /**
94
- * Returns the next inProgress and accounts state based on event message
95
- * @param previousState
96
- * @param action
97
- */
98
-
99
-
100
- const reducer = (previousState, action) => {
101
- const {
102
- type,
103
- payload
104
- } = action;
105
- let newInProgress = previousState.inProgress;
106
-
107
- switch (type) {
108
- case MsalProviderActionType.UNBLOCK_INPROGRESS:
109
- if (previousState.inProgress === InteractionStatus.Startup) {
110
- newInProgress = InteractionStatus.None;
111
- payload.logger.info("MsalProvider - handleRedirectPromise resolved, setting inProgress to 'none'");
112
- }
113
-
114
- break;
115
-
116
- case MsalProviderActionType.EVENT:
117
- const message = payload.message;
118
- const status = EventMessageUtils.getInteractionStatusFromEvent(message, previousState.inProgress);
119
-
120
- if (status) {
121
- payload.logger.info(`MsalProvider - ${message.eventType} results in setting inProgress from ${previousState.inProgress} to ${status}`);
122
- newInProgress = status;
123
- }
124
-
125
- break;
126
-
127
- default:
128
- throw new Error(`Unknown action type: ${type}`);
129
- }
130
-
131
- const currentAccounts = payload.instance.getAllAccounts();
132
-
133
- if (newInProgress !== previousState.inProgress && !accountArraysAreEqual(currentAccounts, previousState.accounts)) {
134
- // Both inProgress and accounts changed
135
- return { ...previousState,
136
- inProgress: newInProgress,
137
- accounts: currentAccounts
138
- };
139
- } else if (newInProgress !== previousState.inProgress) {
140
- // Only only inProgress changed
141
- return { ...previousState,
142
- inProgress: newInProgress
143
- };
144
- } else if (!accountArraysAreEqual(currentAccounts, previousState.accounts)) {
145
- // Only accounts changed
146
- return { ...previousState,
147
- accounts: currentAccounts
148
- };
149
- } else {
150
- // Nothing changed
151
- return previousState;
152
- }
153
- };
154
- /**
155
- * MSAL context provider component. This must be rendered above any other components that use MSAL.
156
- */
157
-
158
-
159
- function MsalProvider(_ref) {
160
- let {
161
- instance,
162
- children
163
- } = _ref;
164
- useEffect(() => {
165
- instance.initializeWrapperLibrary(WrapperSKU.React, version);
166
- }, [instance]); // Create a logger instance for msal-react with the same options as PublicClientApplication
167
-
168
- const logger = useMemo(() => {
169
- return instance.getLogger().clone(name, version);
170
- }, [instance]);
171
- const [state, updateState] = useReducer(reducer, undefined, () => {
172
- // Lazy initialization of the initial state
173
- return {
174
- inProgress: InteractionStatus.Startup,
175
- accounts: instance.getAllAccounts()
176
- };
177
- });
178
- useEffect(() => {
179
- const callbackId = instance.addEventCallback(message => {
180
- updateState({
181
- payload: {
182
- instance,
183
- logger,
184
- message
185
- },
186
- type: MsalProviderActionType.EVENT
187
- });
188
- });
189
- logger.verbose(`MsalProvider - Registered event callback with id: ${callbackId}`);
190
- instance.initialize().then(() => {
191
- instance.handleRedirectPromise().catch(() => {
192
- // Errors should be handled by listening to the LOGIN_FAILURE event
193
- return;
194
- }).finally(() => {
195
- /*
196
- * If handleRedirectPromise returns a cached promise the necessary events may not be fired
197
- * This is a fallback to prevent inProgress from getting stuck in 'startup'
198
- */
199
- updateState({
200
- payload: {
201
- instance,
202
- logger
203
- },
204
- type: MsalProviderActionType.UNBLOCK_INPROGRESS
205
- });
206
- });
207
- });
208
- return () => {
209
- // Remove callback when component unmounts or accounts change
210
- if (callbackId) {
211
- logger.verbose(`MsalProvider - Removing event callback ${callbackId}`);
212
- instance.removeEventCallback(callbackId);
213
- }
214
- };
215
- }, [instance, logger]);
216
- const contextValue = {
217
- instance,
218
- inProgress: state.inProgress,
219
- accounts: state.accounts,
220
- logger
221
- };
222
- return React__default.createElement(MsalContext.Provider, {
223
- value: contextValue
224
- }, children);
225
- }
226
-
227
- /*
228
- * Copyright (c) Microsoft Corporation. All rights reserved.
229
- * Licensed under the MIT License.
230
- */
231
- /**
232
- * Returns Msal Context values
233
- */
234
-
235
- const useMsal = () => useContext(MsalContext);
236
-
237
- /*
238
- * Copyright (c) Microsoft Corporation. All rights reserved.
239
- * Licensed under the MIT License.
240
- */
241
-
242
- function isAuthenticated(allAccounts, matchAccount) {
243
- if (matchAccount && (matchAccount.username || matchAccount.homeAccountId || matchAccount.localAccountId)) {
244
- return !!getAccountByIdentifiers(allAccounts, matchAccount);
245
- }
246
-
247
- return allAccounts.length > 0;
248
- }
249
- /**
250
- * Returns whether or not a user is currently signed-in. Optionally provide 1 or more accountIdentifiers to determine if a specific user is signed-in
251
- * @param matchAccount
252
- */
253
-
254
-
255
- function useIsAuthenticated(matchAccount) {
256
- const {
257
- accounts: allAccounts,
258
- inProgress
259
- } = useMsal();
260
- const [hasAuthenticated, setHasAuthenticated] = useState(() => {
261
- if (inProgress === InteractionStatus.Startup) {
262
- return false;
263
- }
264
-
265
- return isAuthenticated(allAccounts, matchAccount);
266
- });
267
- useEffect(() => {
268
- setHasAuthenticated(isAuthenticated(allAccounts, matchAccount));
269
- }, [allAccounts, matchAccount]);
270
- return hasAuthenticated;
271
- }
272
-
273
- /*
274
- * Copyright (c) Microsoft Corporation. All rights reserved.
275
- * Licensed under the MIT License.
276
- */
277
- /**
278
- * Renders child components if user is authenticated
279
- * @param props
280
- */
281
-
282
- function AuthenticatedTemplate(_ref) {
283
- let {
284
- username,
285
- homeAccountId,
286
- localAccountId,
287
- children
288
- } = _ref;
289
- const context = useMsal();
290
- const accountIdentifier = useMemo(() => {
291
- return {
292
- username,
293
- homeAccountId,
294
- localAccountId
295
- };
296
- }, [username, homeAccountId, localAccountId]);
297
- const isAuthenticated = useIsAuthenticated(accountIdentifier);
298
-
299
- if (isAuthenticated && context.inProgress !== InteractionStatus.Startup) {
300
- return React__default.createElement(React__default.Fragment, null, getChildrenOrFunction(children, context));
301
- }
302
-
303
- return null;
304
- }
305
-
306
- /*
307
- * Copyright (c) Microsoft Corporation. All rights reserved.
308
- * Licensed under the MIT License.
309
- */
310
- /**
311
- * Renders child components if user is unauthenticated
312
- * @param props
313
- */
314
-
315
- function UnauthenticatedTemplate(_ref) {
316
- let {
317
- username,
318
- homeAccountId,
319
- localAccountId,
320
- children
321
- } = _ref;
322
- const context = useMsal();
323
- const accountIdentifier = useMemo(() => {
324
- return {
325
- username,
326
- homeAccountId,
327
- localAccountId
328
- };
329
- }, [username, homeAccountId, localAccountId]);
330
- const isAuthenticated = useIsAuthenticated(accountIdentifier);
331
-
332
- if (!isAuthenticated && context.inProgress !== InteractionStatus.Startup && context.inProgress !== InteractionStatus.HandleRedirect) {
333
- return React__default.createElement(React__default.Fragment, null, getChildrenOrFunction(children, context));
334
- }
335
-
336
- return null;
337
- }
338
-
339
- /*
340
- * Copyright (c) Microsoft Corporation. All rights reserved.
341
- * Licensed under the MIT License.
342
- */
343
-
344
- function getAccount(instance, accountIdentifiers) {
345
- if (!accountIdentifiers || !accountIdentifiers.homeAccountId && !accountIdentifiers.localAccountId && !accountIdentifiers.username) {
346
- // If no account identifiers are provided, return active account
347
- return instance.getActiveAccount();
348
- }
349
-
350
- return getAccountByIdentifiers(instance.getAllAccounts(), accountIdentifiers);
351
- }
352
- /**
353
- * Given 1 or more accountIdentifiers, returns the Account object if the user is signed-in
354
- * @param accountIdentifiers
355
- */
356
-
357
-
358
- function useAccount(accountIdentifiers) {
359
- const {
360
- instance,
361
- inProgress,
362
- logger
363
- } = useMsal();
364
- const [account, setAccount] = useState(() => getAccount(instance, accountIdentifiers));
365
- useEffect(() => {
366
- setAccount(currentAccount => {
367
- const nextAccount = getAccount(instance, accountIdentifiers);
368
-
369
- if (!AccountEntity.accountInfoIsEqual(currentAccount, nextAccount, true)) {
370
- logger.info("useAccount - Updating account");
371
- return nextAccount;
372
- }
373
-
374
- return currentAccount;
375
- });
376
- }, [inProgress, accountIdentifiers, instance, logger]);
377
- return account;
378
- }
379
-
380
- /*
381
- * Copyright (c) Microsoft Corporation. All rights reserved.
382
- * Licensed under the MIT License.
383
- */
384
- const ReactAuthErrorMessage = {
385
- invalidInteractionType: {
386
- code: "invalid_interaction_type",
387
- desc: "The provided interaction type is invalid."
388
- },
389
- unableToFallbackToInteraction: {
390
- code: "unable_to_fallback_to_interaction",
391
- desc: "Interaction is required but another interaction is already in progress. Please try again when the current interaction is complete."
392
- }
393
- };
394
- class ReactAuthError extends AuthError {
395
- constructor(errorCode, errorMessage) {
396
- super(errorCode, errorMessage);
397
- Object.setPrototypeOf(this, ReactAuthError.prototype);
398
- this.name = "ReactAuthError";
399
- }
400
-
401
- static createInvalidInteractionTypeError() {
402
- return new ReactAuthError(ReactAuthErrorMessage.invalidInteractionType.code, ReactAuthErrorMessage.invalidInteractionType.desc);
403
- }
404
-
405
- static createUnableToFallbackToInteractionError() {
406
- return new ReactAuthError(ReactAuthErrorMessage.unableToFallbackToInteraction.code, ReactAuthErrorMessage.unableToFallbackToInteraction.desc);
407
- }
408
-
409
- }
410
-
411
- /*
412
- * Copyright (c) Microsoft Corporation. All rights reserved.
413
- * Licensed under the MIT License.
414
- */
415
- /**
416
- * If a user is not currently signed in this hook invokes a login. Failed logins can be retried using the login callback returned.
417
- * If a user is currently signed in this hook attempts to acquire a token. Subsequent token requests can use the acquireToken callback returned.
418
- * Optionally provide a request object to be used in the login/acquireToken call.
419
- * Optionally provide a specific user that should be logged in.
420
- * @param interactionType
421
- * @param authenticationRequest
422
- * @param accountIdentifiers
423
- */
424
-
425
- function useMsalAuthentication(interactionType, authenticationRequest, accountIdentifiers) {
426
- const {
427
- instance,
428
- inProgress,
429
- logger
430
- } = useMsal();
431
- const isAuthenticated = useIsAuthenticated(accountIdentifiers);
432
- const account = useAccount(accountIdentifiers);
433
- const [[result, error], setResponse] = useState([null, null]); // Used to prevent state updates after unmount
434
-
435
- const mounted = useRef(true);
436
- useEffect(() => {
437
- return () => {
438
- mounted.current = false;
439
- };
440
- }, []); // Boolean used to check if interaction is in progress in acquireTokenSilent fallback. Use Ref instead of state to prevent acquireToken function from being regenerated on each change to interactionInProgress value
441
-
442
- const interactionInProgress = useRef(inProgress !== InteractionStatus.None);
443
- useEffect(() => {
444
- interactionInProgress.current = inProgress !== InteractionStatus.None;
445
- }, [inProgress]); // Flag used to control when the hook calls login/acquireToken
446
-
447
- const shouldAcquireToken = useRef(true);
448
- useEffect(() => {
449
- if (!!error) {
450
- // Errors should be handled by consuming component
451
- shouldAcquireToken.current = false;
452
- return;
453
- }
454
-
455
- if (!!result) {
456
- // Token has already been acquired, consuming component/application is responsible for renewing
457
- shouldAcquireToken.current = false;
458
- return;
459
- }
460
- }, [error, result]);
461
- const login = useCallback(async (callbackInteractionType, callbackRequest) => {
462
- const loginType = callbackInteractionType || interactionType;
463
- const loginRequest = callbackRequest || authenticationRequest;
464
-
465
- switch (loginType) {
466
- case InteractionType.Popup:
467
- logger.verbose("useMsalAuthentication - Calling loginPopup");
468
- return instance.loginPopup(loginRequest);
469
-
470
- case InteractionType.Redirect:
471
- // This promise is not expected to resolve due to full frame redirect
472
- logger.verbose("useMsalAuthentication - Calling loginRedirect");
473
- return instance.loginRedirect(loginRequest).then(null);
474
-
475
- case InteractionType.Silent:
476
- logger.verbose("useMsalAuthentication - Calling ssoSilent");
477
- return instance.ssoSilent(loginRequest);
478
-
479
- default:
480
- throw ReactAuthError.createInvalidInteractionTypeError();
481
- }
482
- }, [instance, interactionType, authenticationRequest, logger]);
483
- const acquireToken = useCallback(async (callbackInteractionType, callbackRequest) => {
484
- const fallbackInteractionType = callbackInteractionType || interactionType;
485
- let tokenRequest;
486
-
487
- if (callbackRequest) {
488
- logger.trace("useMsalAuthentication - acquireToken - Using request provided in the callback");
489
- tokenRequest = { ...callbackRequest
490
- };
491
- } else if (authenticationRequest) {
492
- logger.trace("useMsalAuthentication - acquireToken - Using request provided in the hook");
493
- tokenRequest = { ...authenticationRequest,
494
- scopes: authenticationRequest.scopes || OIDC_DEFAULT_SCOPES
495
- };
496
- } else {
497
- logger.trace("useMsalAuthentication - acquireToken - No request object provided, using default request.");
498
- tokenRequest = {
499
- scopes: OIDC_DEFAULT_SCOPES
500
- };
501
- }
502
-
503
- if (!tokenRequest.account && account) {
504
- logger.trace("useMsalAuthentication - acquireToken - Attaching account to request");
505
- tokenRequest.account = account;
506
- }
507
-
508
- const getToken = async () => {
509
- logger.verbose("useMsalAuthentication - Calling acquireTokenSilent");
510
- return instance.acquireTokenSilent(tokenRequest).catch(async e => {
511
- if (e instanceof InteractionRequiredAuthError) {
512
- if (!interactionInProgress.current) {
513
- logger.error("useMsalAuthentication - Interaction required, falling back to interaction");
514
- return login(fallbackInteractionType, tokenRequest);
515
- } else {
516
- logger.error("useMsalAuthentication - Interaction required but is already in progress. Please try again, if needed, after interaction completes.");
517
- throw ReactAuthError.createUnableToFallbackToInteractionError();
518
- }
519
- }
520
-
521
- throw e;
522
- });
523
- };
524
-
525
- return getToken().then(response => {
526
- if (mounted.current) {
527
- setResponse([response, null]);
528
- }
529
-
530
- return response;
531
- }).catch(e => {
532
- if (mounted.current) {
533
- setResponse([null, e]);
534
- }
535
-
536
- throw e;
537
- });
538
- }, [instance, interactionType, authenticationRequest, logger, account, login]);
539
- useEffect(() => {
540
- const callbackId = instance.addEventCallback(message => {
541
- switch (message.eventType) {
542
- case EventType.LOGIN_SUCCESS:
543
- case EventType.SSO_SILENT_SUCCESS:
544
- if (message.payload) {
545
- setResponse([message.payload, null]);
546
- }
547
-
548
- break;
549
-
550
- case EventType.LOGIN_FAILURE:
551
- case EventType.SSO_SILENT_FAILURE:
552
- if (message.error) {
553
- setResponse([null, message.error]);
554
- }
555
-
556
- break;
557
- }
558
- });
559
- logger.verbose(`useMsalAuthentication - Registered event callback with id: ${callbackId}`);
560
- return () => {
561
- if (callbackId) {
562
- logger.verbose(`useMsalAuthentication - Removing event callback ${callbackId}`);
563
- instance.removeEventCallback(callbackId);
564
- }
565
- };
566
- }, [instance, logger]);
567
- useEffect(() => {
568
- if (shouldAcquireToken.current && inProgress === InteractionStatus.None) {
569
- shouldAcquireToken.current = false;
570
-
571
- if (!isAuthenticated) {
572
- logger.info("useMsalAuthentication - No user is authenticated, attempting to login");
573
- login().catch(() => {
574
- // Errors are saved in state above
575
- return;
576
- });
577
- } else if (account) {
578
- logger.info("useMsalAuthentication - User is authenticated, attempting to acquire token");
579
- acquireToken().catch(() => {
580
- // Errors are saved in state above
581
- return;
582
- });
583
- }
584
- }
585
- }, [isAuthenticated, account, inProgress, login, acquireToken, logger]);
586
- return {
587
- login,
588
- acquireToken,
589
- result,
590
- error
591
- };
592
- }
593
-
594
- /*
595
- * Copyright (c) Microsoft Corporation. All rights reserved.
596
- * Licensed under the MIT License.
597
- */
598
- /**
599
- * Attempts to authenticate user if not already authenticated, then renders child components
600
- * @param props
601
- */
602
-
603
- function MsalAuthenticationTemplate(_ref) {
604
- let {
605
- interactionType,
606
- username,
607
- homeAccountId,
608
- localAccountId,
609
- authenticationRequest,
610
- loadingComponent: LoadingComponent,
611
- errorComponent: ErrorComponent,
612
- children
613
- } = _ref;
614
- const accountIdentifier = useMemo(() => {
615
- return {
616
- username,
617
- homeAccountId,
618
- localAccountId
619
- };
620
- }, [username, homeAccountId, localAccountId]);
621
- const context = useMsal();
622
- const msalAuthResult = useMsalAuthentication(interactionType, authenticationRequest, accountIdentifier);
623
- const isAuthenticated = useIsAuthenticated(accountIdentifier);
624
-
625
- if (msalAuthResult.error && context.inProgress === InteractionStatus.None) {
626
- if (!!ErrorComponent) {
627
- return React__default.createElement(ErrorComponent, Object.assign({}, msalAuthResult));
628
- }
629
-
630
- throw msalAuthResult.error;
631
- }
632
-
633
- if (isAuthenticated) {
634
- return React__default.createElement(React__default.Fragment, null, getChildrenOrFunction(children, msalAuthResult));
635
- }
636
-
637
- if (!!LoadingComponent && context.inProgress !== InteractionStatus.None) {
638
- return React__default.createElement(LoadingComponent, Object.assign({}, context));
639
- }
640
-
641
- return null;
642
- }
643
-
644
- /*
645
- * Copyright (c) Microsoft Corporation. All rights reserved.
646
- * Licensed under the MIT License.
647
- */
648
- /**
649
- * Higher order component wraps provided component with msal by injecting msal context values into the component's props
650
- * @param Component
651
- */
652
-
653
- const withMsal = Component => {
654
- const ComponentWithMsal = props => {
655
- const msal = useMsal();
656
- return React__default.createElement(Component, Object.assign({}, props, {
657
- msalContext: msal
658
- }));
659
- };
660
-
661
- const componentName = Component.displayName || Component.name || "Component";
662
- ComponentWithMsal.displayName = `withMsal(${componentName})`;
663
- return ComponentWithMsal;
664
- };
665
-
666
- export { AuthenticatedTemplate, MsalAuthenticationTemplate, MsalConsumer, MsalContext, MsalProvider, UnauthenticatedTemplate, useAccount, useIsAuthenticated, useMsal, useMsalAuthentication, version, withMsal };
667
- //# sourceMappingURL=msal-react.esm.js.map