UNPKG

@aws-amplify/auth

Version:
38 lines (35 loc) 1.67 kB
import { Amplify, fetchAuthSession } from '@aws-amplify/core'; import { assertTokenProviderConfig, AuthAction } from '@aws-amplify/core/internals/utils'; import { getMFAType, getMFATypes } from '../utils/signInHelpers.mjs'; import { getUser } from '../utils/clients/CognitoIdentityProvider/index.mjs'; import { getRegion } from '../utils/clients/CognitoIdentityProvider/utils.mjs'; import { assertAuthTokens } from '../utils/types.mjs'; import { getAuthUserAgentValue } from '../../../utils/getAuthUserAgentValue.mjs'; // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 /** * Fetches the preferred MFA setting and enabled MFA settings for the user. * * @returns FetchMFAPreferenceOutput * @throws -{@link GetUserException} : error thrown when the service fails to fetch MFA preference * and settings. * @throws AuthTokenConfigException - Thrown when the token provider config is invalid. */ async function fetchMFAPreference() { const authConfig = Amplify.getConfig().Auth?.Cognito; assertTokenProviderConfig(authConfig); const { tokens } = await fetchAuthSession({ forceRefresh: false }); assertAuthTokens(tokens); const { PreferredMfaSetting, UserMFASettingList } = await getUser({ region: getRegion(authConfig.userPoolId), userAgentValue: getAuthUserAgentValue(AuthAction.FetchMFAPreference), }, { AccessToken: tokens.accessToken.toString(), }); return { preferred: getMFAType(PreferredMfaSetting), enabled: getMFATypes(UserMFASettingList), }; } export { fetchMFAPreference }; //# sourceMappingURL=fetchMFAPreference.mjs.map