@aws-amplify/auth
Version:
Auth category of aws-amplify
1 lines • 2.42 kB
Source Map (JSON)
{"version":3,"file":"rememberDevice.mjs","sources":["../../../../../src/providers/cognito/apis/rememberDevice.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Amplify, fetchAuthSession } from '@aws-amplify/core';\nimport { AuthAction, assertTokenProviderConfig, } from '@aws-amplify/core/internals/utils';\nimport { updateDeviceStatus } from '../utils/clients/CognitoIdentityProvider';\nimport { assertAuthTokens, assertDeviceMetadata } from '../utils/types';\nimport { getRegion } from '../utils/clients/CognitoIdentityProvider/utils';\nimport { tokenOrchestrator } from '../tokenProvider';\nimport { getAuthUserAgentValue } from '../../../utils';\n/**\n * Marks device as remembered while authenticated.\n *\n * @throws - {@link UpdateDeviceStatusException} - Cognito service errors thrown when\n * setting device status to remembered using an invalid device key.\n * @throws AuthTokenConfigException - Thrown when the token provider config is invalid.\n */\nexport async function rememberDevice() {\n const authConfig = Amplify.getConfig().Auth?.Cognito;\n assertTokenProviderConfig(authConfig);\n const { tokens } = await fetchAuthSession();\n assertAuthTokens(tokens);\n const deviceMetadata = await tokenOrchestrator?.getDeviceMetadata();\n assertDeviceMetadata(deviceMetadata);\n await updateDeviceStatus({\n region: getRegion(authConfig.userPoolId),\n userAgentValue: getAuthUserAgentValue(AuthAction.RememberDevice),\n }, {\n AccessToken: tokens.accessToken.toString(),\n DeviceKey: deviceMetadata.deviceKey,\n DeviceRememberedStatus: 'remembered',\n });\n}\n"],"names":[],"mappings":";;;;;;;;;;AAAA;AACA;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,eAAe,cAAc,GAAG;AACvC,IAAI,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC;AACzD,IAAI,yBAAyB,CAAC,UAAU,CAAC,CAAC;AAC1C,IAAI,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,gBAAgB,EAAE,CAAC;AAChD,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC;AAC7B,IAAI,MAAM,cAAc,GAAG,MAAM,iBAAiB,EAAE,iBAAiB,EAAE,CAAC;AACxE,IAAI,oBAAoB,CAAC,cAAc,CAAC,CAAC;AACzC,IAAI,MAAM,kBAAkB,CAAC;AAC7B,QAAQ,MAAM,EAAE,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC;AAChD,QAAQ,cAAc,EAAE,qBAAqB,CAAC,UAAU,CAAC,cAAc,CAAC;AACxE,KAAK,EAAE;AACP,QAAQ,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,QAAQ,EAAE;AAClD,QAAQ,SAAS,EAAE,cAAc,CAAC,SAAS;AAC3C,QAAQ,sBAAsB,EAAE,YAAY;AAC5C,KAAK,CAAC,CAAC;AACP;;;;"}