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

37 lines
1.3 KiB
JavaScript
Executable file

/*! @azure/msal-react v3.0.17 2025-08-05 */
'use strict';
import { useMemo } from 'react';
import { useMsal } from './useMsal.js';
import { InteractionStatus } from '@azure/msal-browser';
import { getAccountByIdentifiers } from '../utils/utilities.js';
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License.
*/
function isAuthenticated(allAccounts, matchAccount) {
if (matchAccount &&
(matchAccount.username ||
matchAccount.homeAccountId ||
matchAccount.localAccountId)) {
return !!getAccountByIdentifiers(allAccounts, matchAccount);
}
return allAccounts.length > 0;
}
/**
* 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
* @param matchAccount
*/
function useIsAuthenticated(matchAccount) {
const { accounts: allAccounts, inProgress } = useMsal();
const isUserAuthenticated = useMemo(() => {
if (inProgress === InteractionStatus.Startup) {
return false;
}
return isAuthenticated(allAccounts, matchAccount);
}, [allAccounts, inProgress, matchAccount]);
return isUserAuthenticated;
}
export { useIsAuthenticated };
//# sourceMappingURL=useIsAuthenticated.js.map