diff --git a/packages/core/src/awsClients/cognitoIdentity/base.ts b/packages/core/src/awsClients/cognitoIdentity/base.ts index cb6cfacb32b..06a2566d27d 100644 --- a/packages/core/src/awsClients/cognitoIdentity/base.ts +++ b/packages/core/src/awsClients/cognitoIdentity/base.ts @@ -1,6 +1,8 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 +import { Amplify } from '@aws-amplify/core'; + import { Endpoint, EndpointResolverOptions, @@ -29,11 +31,17 @@ const SERVICE_NAME = 'cognito-identity'; /** * The endpoint resolver function that returns the endpoint URL for a given region. */ -const endpointResolver = ({ region }: EndpointResolverOptions) => ({ - url: new AmplifyUrl( - `https://cognito-identity.${region}.${getDnsSuffix(region)}`, - ), -}); +const endpointResolver = ({ region }: EndpointResolverOptions) => { + const authConfig = Amplify.getConfig().Auth?.Cognito; + const customURL = authConfig?.userPoolEndpoint; + const defaultURL = new AmplifyUrl( + `https://${SERVICE_NAME}.${region}.${getDnsSuffix(region)}`, + ); + + return { + url: customURL ? new AmplifyUrl(customURL) : defaultURL, + }; +}; /** * A Cognito Identity-specific middleware that disables caching for all requests. diff --git a/packages/core/src/singleton/Auth/types.ts b/packages/core/src/singleton/Auth/types.ts index 239810e8771..5e38f34f157 100644 --- a/packages/core/src/singleton/Auth/types.ts +++ b/packages/core/src/singleton/Auth/types.ts @@ -135,12 +135,14 @@ export interface AuthIdentityPoolConfig { export interface CognitoIdentityPoolConfig { identityPoolId: string; + identityPoolEndpoint?: string; allowGuestAccess?: boolean; } export interface AuthUserPoolConfig { Cognito: CognitoUserPoolConfig & { identityPoolId?: never; + identityPoolEndpoint?: never; allowGuestAccess?: never; }; }