@azure/msal-react 2.0.0-alpha.0 → 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 +64 -64
  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,4 +1,4 @@
1
- /*! @azure/msal-react v2.0.0-alpha.0 2023-05-03 */
1
+ /*! @azure/msal-react v2.0.0-alpha.2 2023-05-17 */
2
2
  'use strict';
3
3
  import React__default, { useEffect, useMemo, useReducer } from 'react';
4
4
  import { WrapperSKU, InteractionStatus, EventMessageUtils } from '@azure/msal-browser';
@@ -6,136 +6,136 @@ import { MsalContext } from './MsalContext.js';
6
6
  import { accountArraysAreEqual } from './utils/utilities.js';
7
7
  import { version, name } from './packageMetadata.js';
8
8
 
9
- /*
10
- * Copyright (c) Microsoft Corporation. All rights reserved.
11
- * Licensed under the MIT License.
12
- */
13
- var MsalProviderActionType;
14
- (function (MsalProviderActionType) {
15
- MsalProviderActionType["UNBLOCK_INPROGRESS"] = "UNBLOCK_INPROGRESS";
16
- MsalProviderActionType["EVENT"] = "EVENT";
17
- })(MsalProviderActionType || (MsalProviderActionType = {}));
18
- /**
19
- * Returns the next inProgress and accounts state based on event message
20
- * @param previousState
21
- * @param action
22
- */
23
- const reducer = (previousState, action) => {
24
- const { type, payload } = action;
25
- let newInProgress = previousState.inProgress;
26
- switch (type) {
27
- case MsalProviderActionType.UNBLOCK_INPROGRESS:
28
- if (previousState.inProgress === InteractionStatus.Startup) {
29
- newInProgress = InteractionStatus.None;
30
- payload.logger.info("MsalProvider - handleRedirectPromise resolved, setting inProgress to 'none'");
31
- }
32
- break;
33
- case MsalProviderActionType.EVENT:
34
- const message = payload.message;
35
- const status = EventMessageUtils.getInteractionStatusFromEvent(message, previousState.inProgress);
36
- if (status) {
37
- payload.logger.info(`MsalProvider - ${message.eventType} results in setting inProgress from ${previousState.inProgress} to ${status}`);
38
- newInProgress = status;
39
- }
40
- break;
41
- default:
42
- throw new Error(`Unknown action type: ${type}`);
43
- }
44
- const currentAccounts = payload.instance.getAllAccounts();
45
- if (newInProgress !== previousState.inProgress &&
46
- !accountArraysAreEqual(currentAccounts, previousState.accounts)) {
47
- // Both inProgress and accounts changed
48
- return {
49
- ...previousState,
50
- inProgress: newInProgress,
51
- accounts: currentAccounts,
52
- };
53
- }
54
- else if (newInProgress !== previousState.inProgress) {
55
- // Only only inProgress changed
56
- return {
57
- ...previousState,
58
- inProgress: newInProgress,
59
- };
60
- }
61
- else if (!accountArraysAreEqual(currentAccounts, previousState.accounts)) {
62
- // Only accounts changed
63
- return {
64
- ...previousState,
65
- accounts: currentAccounts,
66
- };
67
- }
68
- else {
69
- // Nothing changed
70
- return previousState;
71
- }
72
- };
73
- /**
74
- * MSAL context provider component. This must be rendered above any other components that use MSAL.
75
- */
76
- function MsalProvider({ instance, children, }) {
77
- useEffect(() => {
78
- instance.initializeWrapperLibrary(WrapperSKU.React, version);
79
- }, [instance]);
80
- // Create a logger instance for msal-react with the same options as PublicClientApplication
81
- const logger = useMemo(() => {
82
- return instance.getLogger().clone(name, version);
83
- }, [instance]);
84
- const [state, updateState] = useReducer(reducer, undefined, () => {
85
- // Lazy initialization of the initial state
86
- return {
87
- inProgress: InteractionStatus.Startup,
88
- accounts: instance.getAllAccounts(),
89
- };
90
- });
91
- useEffect(() => {
92
- const callbackId = instance.addEventCallback((message) => {
93
- updateState({
94
- payload: {
95
- instance,
96
- logger,
97
- message,
98
- },
99
- type: MsalProviderActionType.EVENT,
100
- });
101
- });
102
- logger.verbose(`MsalProvider - Registered event callback with id: ${callbackId}`);
103
- instance.initialize().then(() => {
104
- instance
105
- .handleRedirectPromise()
106
- .catch(() => {
107
- // Errors should be handled by listening to the LOGIN_FAILURE event
108
- return;
109
- })
110
- .finally(() => {
111
- /*
112
- * If handleRedirectPromise returns a cached promise the necessary events may not be fired
113
- * This is a fallback to prevent inProgress from getting stuck in 'startup'
114
- */
115
- updateState({
116
- payload: {
117
- instance,
118
- logger,
119
- },
120
- type: MsalProviderActionType.UNBLOCK_INPROGRESS,
121
- });
122
- });
123
- });
124
- return () => {
125
- // Remove callback when component unmounts or accounts change
126
- if (callbackId) {
127
- logger.verbose(`MsalProvider - Removing event callback ${callbackId}`);
128
- instance.removeEventCallback(callbackId);
129
- }
130
- };
131
- }, [instance, logger]);
132
- const contextValue = {
133
- instance,
134
- inProgress: state.inProgress,
135
- accounts: state.accounts,
136
- logger,
137
- };
138
- return (React__default.createElement(MsalContext.Provider, { value: contextValue }, children));
9
+ /*
10
+ * Copyright (c) Microsoft Corporation. All rights reserved.
11
+ * Licensed under the MIT License.
12
+ */
13
+ var MsalProviderActionType;
14
+ (function (MsalProviderActionType) {
15
+ MsalProviderActionType["UNBLOCK_INPROGRESS"] = "UNBLOCK_INPROGRESS";
16
+ MsalProviderActionType["EVENT"] = "EVENT";
17
+ })(MsalProviderActionType || (MsalProviderActionType = {}));
18
+ /**
19
+ * Returns the next inProgress and accounts state based on event message
20
+ * @param previousState
21
+ * @param action
22
+ */
23
+ const reducer = (previousState, action) => {
24
+ const { type, payload } = action;
25
+ let newInProgress = previousState.inProgress;
26
+ switch (type) {
27
+ case MsalProviderActionType.UNBLOCK_INPROGRESS:
28
+ if (previousState.inProgress === InteractionStatus.Startup) {
29
+ newInProgress = InteractionStatus.None;
30
+ payload.logger.info("MsalProvider - handleRedirectPromise resolved, setting inProgress to 'none'");
31
+ }
32
+ break;
33
+ case MsalProviderActionType.EVENT:
34
+ const message = payload.message;
35
+ const status = EventMessageUtils.getInteractionStatusFromEvent(message, previousState.inProgress);
36
+ if (status) {
37
+ payload.logger.info(`MsalProvider - ${message.eventType} results in setting inProgress from ${previousState.inProgress} to ${status}`);
38
+ newInProgress = status;
39
+ }
40
+ break;
41
+ default:
42
+ throw new Error(`Unknown action type: ${type}`);
43
+ }
44
+ const currentAccounts = payload.instance.getAllAccounts();
45
+ if (newInProgress !== previousState.inProgress &&
46
+ !accountArraysAreEqual(currentAccounts, previousState.accounts)) {
47
+ // Both inProgress and accounts changed
48
+ return {
49
+ ...previousState,
50
+ inProgress: newInProgress,
51
+ accounts: currentAccounts,
52
+ };
53
+ }
54
+ else if (newInProgress !== previousState.inProgress) {
55
+ // Only only inProgress changed
56
+ return {
57
+ ...previousState,
58
+ inProgress: newInProgress,
59
+ };
60
+ }
61
+ else if (!accountArraysAreEqual(currentAccounts, previousState.accounts)) {
62
+ // Only accounts changed
63
+ return {
64
+ ...previousState,
65
+ accounts: currentAccounts,
66
+ };
67
+ }
68
+ else {
69
+ // Nothing changed
70
+ return previousState;
71
+ }
72
+ };
73
+ /**
74
+ * MSAL context provider component. This must be rendered above any other components that use MSAL.
75
+ */
76
+ function MsalProvider({ instance, children, }) {
77
+ useEffect(() => {
78
+ instance.initializeWrapperLibrary(WrapperSKU.React, version);
79
+ }, [instance]);
80
+ // Create a logger instance for msal-react with the same options as PublicClientApplication
81
+ const logger = useMemo(() => {
82
+ return instance.getLogger().clone(name, version);
83
+ }, [instance]);
84
+ const [state, updateState] = useReducer(reducer, undefined, () => {
85
+ // Lazy initialization of the initial state
86
+ return {
87
+ inProgress: InteractionStatus.Startup,
88
+ accounts: instance.getAllAccounts(),
89
+ };
90
+ });
91
+ useEffect(() => {
92
+ const callbackId = instance.addEventCallback((message) => {
93
+ updateState({
94
+ payload: {
95
+ instance,
96
+ logger,
97
+ message,
98
+ },
99
+ type: MsalProviderActionType.EVENT,
100
+ });
101
+ });
102
+ logger.verbose(`MsalProvider - Registered event callback with id: ${callbackId}`);
103
+ instance.initialize().then(() => {
104
+ instance
105
+ .handleRedirectPromise()
106
+ .catch(() => {
107
+ // Errors should be handled by listening to the LOGIN_FAILURE event
108
+ return;
109
+ })
110
+ .finally(() => {
111
+ /*
112
+ * If handleRedirectPromise returns a cached promise the necessary events may not be fired
113
+ * This is a fallback to prevent inProgress from getting stuck in 'startup'
114
+ */
115
+ updateState({
116
+ payload: {
117
+ instance,
118
+ logger,
119
+ },
120
+ type: MsalProviderActionType.UNBLOCK_INPROGRESS,
121
+ });
122
+ });
123
+ });
124
+ return () => {
125
+ // Remove callback when component unmounts or accounts change
126
+ if (callbackId) {
127
+ logger.verbose(`MsalProvider - Removing event callback ${callbackId}`);
128
+ instance.removeEventCallback(callbackId);
129
+ }
130
+ };
131
+ }, [instance, logger]);
132
+ const contextValue = {
133
+ instance,
134
+ inProgress: state.inProgress,
135
+ accounts: state.accounts,
136
+ logger,
137
+ };
138
+ return (React__default.createElement(MsalContext.Provider, { value: contextValue }, children));
139
139
  }
140
140
 
141
141
  export { MsalProvider };
@@ -1,8 +1,8 @@
1
- import React, { PropsWithChildren } from "react";
2
- import { AccountIdentifiers } from "../types/AccountIdentifiers";
3
- export type AuthenticatedTemplateProps = PropsWithChildren<AccountIdentifiers>;
4
- /**
5
- * Renders child components if user is authenticated
6
- * @param props
7
- */
8
- export declare function AuthenticatedTemplate({ username, homeAccountId, localAccountId, children, }: AuthenticatedTemplateProps): React.ReactElement | null;
1
+ import React, { PropsWithChildren } from "react";
2
+ import { AccountIdentifiers } from "../types/AccountIdentifiers";
3
+ export type AuthenticatedTemplateProps = PropsWithChildren<AccountIdentifiers>;
4
+ /**
5
+ * Renders child components if user is authenticated
6
+ * @param props
7
+ */
8
+ export declare function AuthenticatedTemplate({ username, homeAccountId, localAccountId, children, }: AuthenticatedTemplateProps): React.ReactElement | null;
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-react v2.0.0-alpha.0 2023-05-03 */
1
+ /*! @azure/msal-react v2.0.0-alpha.2 2023-05-17 */
2
2
  'use strict';
3
3
  import React__default, { useMemo } from 'react';
4
4
  import { getChildrenOrFunction } from '../utils/utilities.js';
@@ -6,28 +6,28 @@ import { useMsal } from '../hooks/useMsal.js';
6
6
  import { useIsAuthenticated } from '../hooks/useIsAuthenticated.js';
7
7
  import { InteractionStatus } from '@azure/msal-browser';
8
8
 
9
- /*
10
- * Copyright (c) Microsoft Corporation. All rights reserved.
11
- * Licensed under the MIT License.
12
- */
13
- /**
14
- * Renders child components if user is authenticated
15
- * @param props
16
- */
17
- function AuthenticatedTemplate({ username, homeAccountId, localAccountId, children, }) {
18
- const context = useMsal();
19
- const accountIdentifier = useMemo(() => {
20
- return {
21
- username,
22
- homeAccountId,
23
- localAccountId,
24
- };
25
- }, [username, homeAccountId, localAccountId]);
26
- const isAuthenticated = useIsAuthenticated(accountIdentifier);
27
- if (isAuthenticated && context.inProgress !== InteractionStatus.Startup) {
28
- return (React__default.createElement(React__default.Fragment, null, getChildrenOrFunction(children, context)));
29
- }
30
- return null;
9
+ /*
10
+ * Copyright (c) Microsoft Corporation. All rights reserved.
11
+ * Licensed under the MIT License.
12
+ */
13
+ /**
14
+ * Renders child components if user is authenticated
15
+ * @param props
16
+ */
17
+ function AuthenticatedTemplate({ username, homeAccountId, localAccountId, children, }) {
18
+ const context = useMsal();
19
+ const accountIdentifier = useMemo(() => {
20
+ return {
21
+ username,
22
+ homeAccountId,
23
+ localAccountId,
24
+ };
25
+ }, [username, homeAccountId, localAccountId]);
26
+ const isAuthenticated = useIsAuthenticated(accountIdentifier);
27
+ if (isAuthenticated && context.inProgress !== InteractionStatus.Startup) {
28
+ return (React__default.createElement(React__default.Fragment, null, getChildrenOrFunction(children, context)));
29
+ }
30
+ return null;
31
31
  }
32
32
 
33
33
  export { AuthenticatedTemplate };
@@ -1,16 +1,16 @@
1
- import React, { PropsWithChildren } from "react";
2
- import { AccountIdentifiers } from "../types/AccountIdentifiers";
3
- import { MsalAuthenticationResult } from "../hooks/useMsalAuthentication";
4
- import { InteractionType, PopupRequest, RedirectRequest, SsoSilentRequest } from "@azure/msal-browser";
5
- import { IMsalContext } from "../MsalContext";
6
- export type MsalAuthenticationProps = PropsWithChildren<AccountIdentifiers & {
7
- interactionType: InteractionType;
8
- authenticationRequest?: PopupRequest | RedirectRequest | SsoSilentRequest;
9
- loadingComponent?: React.ElementType<IMsalContext>;
10
- errorComponent?: React.ElementType<MsalAuthenticationResult>;
11
- }>;
12
- /**
13
- * Attempts to authenticate user if not already authenticated, then renders child components
14
- * @param props
15
- */
16
- export declare function MsalAuthenticationTemplate({ interactionType, username, homeAccountId, localAccountId, authenticationRequest, loadingComponent: LoadingComponent, errorComponent: ErrorComponent, children, }: MsalAuthenticationProps): React.ReactElement | null;
1
+ import React, { PropsWithChildren } from "react";
2
+ import { AccountIdentifiers } from "../types/AccountIdentifiers";
3
+ import { MsalAuthenticationResult } from "../hooks/useMsalAuthentication";
4
+ import { InteractionType, PopupRequest, RedirectRequest, SsoSilentRequest } from "@azure/msal-browser";
5
+ import { IMsalContext } from "../MsalContext";
6
+ export type MsalAuthenticationProps = PropsWithChildren<AccountIdentifiers & {
7
+ interactionType: InteractionType;
8
+ authenticationRequest?: PopupRequest | RedirectRequest | SsoSilentRequest;
9
+ loadingComponent?: React.ElementType<IMsalContext>;
10
+ errorComponent?: React.ElementType<MsalAuthenticationResult>;
11
+ }>;
12
+ /**
13
+ * Attempts to authenticate user if not already authenticated, then renders child components
14
+ * @param props
15
+ */
16
+ export declare function MsalAuthenticationTemplate({ interactionType, username, homeAccountId, localAccountId, authenticationRequest, loadingComponent: LoadingComponent, errorComponent: ErrorComponent, children, }: MsalAuthenticationProps): React.ReactElement | null;
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-react v2.0.0-alpha.0 2023-05-03 */
1
+ /*! @azure/msal-react v2.0.0-alpha.2 2023-05-17 */
2
2
  'use strict';
3
3
  import React__default, { useMemo } from 'react';
4
4
  import { getChildrenOrFunction } from '../utils/utilities.js';
@@ -7,38 +7,38 @@ import { useMsalAuthentication } from '../hooks/useMsalAuthentication.js';
7
7
  import { useIsAuthenticated } from '../hooks/useIsAuthenticated.js';
8
8
  import { InteractionStatus } from '@azure/msal-browser';
9
9
 
10
- /*
11
- * Copyright (c) Microsoft Corporation. All rights reserved.
12
- * Licensed under the MIT License.
13
- */
14
- /**
15
- * Attempts to authenticate user if not already authenticated, then renders child components
16
- * @param props
17
- */
18
- function MsalAuthenticationTemplate({ interactionType, username, homeAccountId, localAccountId, authenticationRequest, loadingComponent: LoadingComponent, errorComponent: ErrorComponent, children, }) {
19
- const accountIdentifier = useMemo(() => {
20
- return {
21
- username,
22
- homeAccountId,
23
- localAccountId,
24
- };
25
- }, [username, homeAccountId, localAccountId]);
26
- const context = useMsal();
27
- const msalAuthResult = useMsalAuthentication(interactionType, authenticationRequest, accountIdentifier);
28
- const isAuthenticated = useIsAuthenticated(accountIdentifier);
29
- if (msalAuthResult.error && context.inProgress === InteractionStatus.None) {
30
- if (!!ErrorComponent) {
31
- return React__default.createElement(ErrorComponent, { ...msalAuthResult });
32
- }
33
- throw msalAuthResult.error;
34
- }
35
- if (isAuthenticated) {
36
- return (React__default.createElement(React__default.Fragment, null, getChildrenOrFunction(children, msalAuthResult)));
37
- }
38
- if (!!LoadingComponent && context.inProgress !== InteractionStatus.None) {
39
- return React__default.createElement(LoadingComponent, { ...context });
40
- }
41
- return null;
10
+ /*
11
+ * Copyright (c) Microsoft Corporation. All rights reserved.
12
+ * Licensed under the MIT License.
13
+ */
14
+ /**
15
+ * Attempts to authenticate user if not already authenticated, then renders child components
16
+ * @param props
17
+ */
18
+ function MsalAuthenticationTemplate({ interactionType, username, homeAccountId, localAccountId, authenticationRequest, loadingComponent: LoadingComponent, errorComponent: ErrorComponent, children, }) {
19
+ const accountIdentifier = useMemo(() => {
20
+ return {
21
+ username,
22
+ homeAccountId,
23
+ localAccountId,
24
+ };
25
+ }, [username, homeAccountId, localAccountId]);
26
+ const context = useMsal();
27
+ const msalAuthResult = useMsalAuthentication(interactionType, authenticationRequest, accountIdentifier);
28
+ const isAuthenticated = useIsAuthenticated(accountIdentifier);
29
+ if (msalAuthResult.error && context.inProgress === InteractionStatus.None) {
30
+ if (!!ErrorComponent) {
31
+ return React__default.createElement(ErrorComponent, { ...msalAuthResult });
32
+ }
33
+ throw msalAuthResult.error;
34
+ }
35
+ if (isAuthenticated) {
36
+ return (React__default.createElement(React__default.Fragment, null, getChildrenOrFunction(children, msalAuthResult)));
37
+ }
38
+ if (!!LoadingComponent && context.inProgress !== InteractionStatus.None) {
39
+ return React__default.createElement(LoadingComponent, { ...context });
40
+ }
41
+ return null;
42
42
  }
43
43
 
44
44
  export { MsalAuthenticationTemplate };
@@ -1,8 +1,8 @@
1
- import React, { PropsWithChildren } from "react";
2
- import { AccountIdentifiers } from "../types/AccountIdentifiers";
3
- export type UnauthenticatedTemplateProps = PropsWithChildren<AccountIdentifiers>;
4
- /**
5
- * Renders child components if user is unauthenticated
6
- * @param props
7
- */
8
- export declare function UnauthenticatedTemplate({ username, homeAccountId, localAccountId, children, }: UnauthenticatedTemplateProps): React.ReactElement | null;
1
+ import React, { PropsWithChildren } from "react";
2
+ import { AccountIdentifiers } from "../types/AccountIdentifiers";
3
+ export type UnauthenticatedTemplateProps = PropsWithChildren<AccountIdentifiers>;
4
+ /**
5
+ * Renders child components if user is unauthenticated
6
+ * @param props
7
+ */
8
+ export declare function UnauthenticatedTemplate({ username, homeAccountId, localAccountId, children, }: UnauthenticatedTemplateProps): React.ReactElement | null;
@@ -1,4 +1,4 @@
1
- /*! @azure/msal-react v2.0.0-alpha.0 2023-05-03 */
1
+ /*! @azure/msal-react v2.0.0-alpha.2 2023-05-17 */
2
2
  'use strict';
3
3
  import React__default, { useMemo } from 'react';
4
4
  import { useMsal } from '../hooks/useMsal.js';
@@ -6,30 +6,30 @@ import { useIsAuthenticated } from '../hooks/useIsAuthenticated.js';
6
6
  import { getChildrenOrFunction } from '../utils/utilities.js';
7
7
  import { InteractionStatus } from '@azure/msal-browser';
8
8
 
9
- /*
10
- * Copyright (c) Microsoft Corporation. All rights reserved.
11
- * Licensed under the MIT License.
12
- */
13
- /**
14
- * Renders child components if user is unauthenticated
15
- * @param props
16
- */
17
- function UnauthenticatedTemplate({ username, homeAccountId, localAccountId, children, }) {
18
- const context = useMsal();
19
- const accountIdentifier = useMemo(() => {
20
- return {
21
- username,
22
- homeAccountId,
23
- localAccountId,
24
- };
25
- }, [username, homeAccountId, localAccountId]);
26
- const isAuthenticated = useIsAuthenticated(accountIdentifier);
27
- if (!isAuthenticated &&
28
- context.inProgress !== InteractionStatus.Startup &&
29
- context.inProgress !== InteractionStatus.HandleRedirect) {
30
- return (React__default.createElement(React__default.Fragment, null, getChildrenOrFunction(children, context)));
31
- }
32
- return null;
9
+ /*
10
+ * Copyright (c) Microsoft Corporation. All rights reserved.
11
+ * Licensed under the MIT License.
12
+ */
13
+ /**
14
+ * Renders child components if user is unauthenticated
15
+ * @param props
16
+ */
17
+ function UnauthenticatedTemplate({ username, homeAccountId, localAccountId, children, }) {
18
+ const context = useMsal();
19
+ const accountIdentifier = useMemo(() => {
20
+ return {
21
+ username,
22
+ homeAccountId,
23
+ localAccountId,
24
+ };
25
+ }, [username, homeAccountId, localAccountId]);
26
+ const isAuthenticated = useIsAuthenticated(accountIdentifier);
27
+ if (!isAuthenticated &&
28
+ context.inProgress !== InteractionStatus.Startup &&
29
+ context.inProgress !== InteractionStatus.HandleRedirect) {
30
+ return (React__default.createElement(React__default.Fragment, null, getChildrenOrFunction(children, context)));
31
+ }
32
+ return null;
33
33
  }
34
34
 
35
35
  export { UnauthenticatedTemplate };
@@ -1,11 +1,11 @@
1
- import React from "react";
2
- import { IMsalContext } from "../MsalContext";
3
- import { Subtract } from "../utils/utilities";
4
- export type WithMsalProps = {
5
- msalContext: IMsalContext;
6
- };
7
- /**
8
- * Higher order component wraps provided component with msal by injecting msal context values into the component's props
9
- * @param Component
10
- */
11
- export declare const withMsal: <P extends WithMsalProps>(Component: React.ComponentType<P>) => React.FunctionComponent<Subtract<P, WithMsalProps>>;
1
+ import React from "react";
2
+ import { IMsalContext } from "../MsalContext";
3
+ import { Subtract } from "../utils/utilities";
4
+ export type WithMsalProps = {
5
+ msalContext: IMsalContext;
6
+ };
7
+ /**
8
+ * Higher order component wraps provided component with msal by injecting msal context values into the component's props
9
+ * @param Component
10
+ */
11
+ export declare const withMsal: <P extends WithMsalProps>(Component: React.ComponentType<P>) => React.FunctionComponent<Subtract<P, WithMsalProps>>;
@@ -1,24 +1,24 @@
1
- /*! @azure/msal-react v2.0.0-alpha.0 2023-05-03 */
1
+ /*! @azure/msal-react v2.0.0-alpha.2 2023-05-17 */
2
2
  'use strict';
3
3
  import React__default from 'react';
4
4
  import { useMsal } from '../hooks/useMsal.js';
5
5
 
6
- /*
7
- * Copyright (c) Microsoft Corporation. All rights reserved.
8
- * Licensed under the MIT License.
9
- */
10
- /**
11
- * Higher order component wraps provided component with msal by injecting msal context values into the component's props
12
- * @param Component
13
- */
14
- const withMsal = (Component) => {
15
- const ComponentWithMsal = (props) => {
16
- const msal = useMsal();
17
- return React__default.createElement(Component, { ...props, msalContext: msal });
18
- };
19
- const componentName = Component.displayName || Component.name || "Component";
20
- ComponentWithMsal.displayName = `withMsal(${componentName})`;
21
- return ComponentWithMsal;
6
+ /*
7
+ * Copyright (c) Microsoft Corporation. All rights reserved.
8
+ * Licensed under the MIT License.
9
+ */
10
+ /**
11
+ * Higher order component wraps provided component with msal by injecting msal context values into the component's props
12
+ * @param Component
13
+ */
14
+ const withMsal = (Component) => {
15
+ const ComponentWithMsal = (props) => {
16
+ const msal = useMsal();
17
+ return React__default.createElement(Component, { ...props, msalContext: msal });
18
+ };
19
+ const componentName = Component.displayName || Component.name || "Component";
20
+ ComponentWithMsal.displayName = `withMsal(${componentName})`;
21
+ return ComponentWithMsal;
22
22
  };
23
23
 
24
24
  export { withMsal };
@@ -1,16 +1,16 @@
1
- import { AuthError } from "@azure/msal-browser";
2
- export declare const ReactAuthErrorMessage: {
3
- invalidInteractionType: {
4
- code: string;
5
- desc: string;
6
- };
7
- unableToFallbackToInteraction: {
8
- code: string;
9
- desc: string;
10
- };
11
- };
12
- export declare class ReactAuthError extends AuthError {
13
- constructor(errorCode: string, errorMessage?: string);
14
- static createInvalidInteractionTypeError(): ReactAuthError;
15
- static createUnableToFallbackToInteractionError(): ReactAuthError;
16
- }
1
+ import { AuthError } from "@azure/msal-browser";
2
+ export declare const ReactAuthErrorMessage: {
3
+ invalidInteractionType: {
4
+ code: string;
5
+ desc: string;
6
+ };
7
+ unableToFallbackToInteraction: {
8
+ code: string;
9
+ desc: string;
10
+ };
11
+ };
12
+ export declare class ReactAuthError extends AuthError {
13
+ constructor(errorCode: string, errorMessage?: string);
14
+ static createInvalidInteractionTypeError(): ReactAuthError;
15
+ static createUnableToFallbackToInteractionError(): ReactAuthError;
16
+ }