37 lines
1.3 KiB
JavaScript
Executable file
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
|