Skip to content

Commit

Permalink
add identityPoolEndpoint config to allow using a custom Cognito-Ident…
Browse files Browse the repository at this point in the history
…ity endpoint
  • Loading branch information
whummer committed Jun 30, 2024
1 parent b6de5f9 commit aca9ec0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
18 changes: 13 additions & 5 deletions packages/core/src/awsClients/cognitoIdentity/base.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/singleton/Auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
Expand Down

0 comments on commit aca9ec0

Please sign in to comment.