semblance-dev/node_modules/@azure/msal-react/dist/components/MsalAuthenticationTemplate.js
2025-12-19 19:26:16 +00:00

45 lines
1.9 KiB
JavaScript
Executable file

/*! @azure/msal-react v3.0.17 2025-08-05 */
'use strict';
import React__default, { useMemo } from 'react';
import { getChildrenOrFunction } from '../utils/utilities.js';
import { useMsal } from '../hooks/useMsal.js';
import { useMsalAuthentication } from '../hooks/useMsalAuthentication.js';
import { useIsAuthenticated } from '../hooks/useIsAuthenticated.js';
import { InteractionStatus } from '@azure/msal-browser';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
/**
* Attempts to authenticate user if not already authenticated, then renders child components
* @param props
*/
function MsalAuthenticationTemplate({ interactionType, username, homeAccountId, localAccountId, authenticationRequest, loadingComponent: LoadingComponent, errorComponent: ErrorComponent, children, }) {
const accountIdentifier = useMemo(() => {
return {
username,
homeAccountId,
localAccountId,
};
}, [username, homeAccountId, localAccountId]);
const context = useMsal();
const msalAuthResult = useMsalAuthentication(interactionType, authenticationRequest, accountIdentifier);
const isAuthenticated = useIsAuthenticated(accountIdentifier);
if (msalAuthResult.error && context.inProgress === InteractionStatus.None) {
if (!!ErrorComponent) {
return React__default.createElement(ErrorComponent, { ...msalAuthResult });
}
throw msalAuthResult.error;
}
if (isAuthenticated) {
return (React__default.createElement(React__default.Fragment, null, getChildrenOrFunction(children, msalAuthResult)));
}
if (!!LoadingComponent && context.inProgress !== InteractionStatus.None) {
return React__default.createElement(LoadingComponent, { ...context });
}
return null;
}
export { MsalAuthenticationTemplate };
//# sourceMappingURL=MsalAuthenticationTemplate.js.map