Skip to content

Commit f991f68

Browse files
committed
chore: adding warnings regarding using custom endpoints
1 parent 5155098 commit f991f68

File tree

3 files changed

+78
-0
lines changed

3 files changed

+78
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { ConsoleLogger } from '../../../src/Logger';
2+
import { AuthClass } from '../../../src/singleton/Auth';
3+
4+
jest.mock('../../../src/Logger', () => {
5+
const warn = jest.fn();
6+
7+
return {
8+
ConsoleLogger: jest.fn(() => ({
9+
warn,
10+
})),
11+
};
12+
});
13+
14+
describe('Auth', () => {
15+
const auth = new AuthClass();
16+
const logger = new ConsoleLogger('Auth');
17+
const mockedWarn = logger.warn as jest.Mock;
18+
19+
describe('configure', () => {
20+
const mockConfig = {
21+
userPoolClientId: 'userPoolClientId',
22+
userPoolId: 'userPoolId',
23+
};
24+
25+
it('prints warning when use custom endpoint for Cognito User Pool', () => {
26+
auth.configure({
27+
Cognito: {
28+
...mockConfig,
29+
userPoolEndpoint: 'https://custom-endpoint.com',
30+
},
31+
});
32+
33+
expect(mockedWarn).toHaveBeenCalledWith(
34+
expect.stringContaining('Amazon Cognito User Pool'),
35+
);
36+
});
37+
38+
it('prints warning when use custom endpoint for Cognito Identity Pool', () => {
39+
auth.configure({
40+
Cognito: {
41+
...mockConfig,
42+
identityPoolId: 'identityPoolId',
43+
identityPoolEndpoint: 'https://custom-endpoint.com',
44+
},
45+
});
46+
47+
expect(mockedWarn).toHaveBeenCalledWith(
48+
expect.stringContaining('Amazon Cognito Identity Pool'),
49+
);
50+
});
51+
});
52+
});

packages/core/src/singleton/Auth/index.ts

+20
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3+
import { ConsoleLogger } from '../../Logger';
4+
35
import {
46
AuthConfig,
57
AuthSession,
@@ -9,6 +11,8 @@ import {
911
LibraryAuthOptions,
1012
} from './types';
1113

14+
const logger = new ConsoleLogger('Auth');
15+
1216
export function isTokenExpired({
1317
expiresAt,
1418
clockDrift,
@@ -41,6 +45,19 @@ export class AuthClass {
4145
): void {
4246
this.authConfig = authResourcesConfig;
4347
this.authOptions = authOptions;
48+
49+
if (authResourcesConfig && authResourcesConfig.Cognito?.userPoolEndpoint) {
50+
logger.warn(getCustomEndpointWarningMessage('Amazon Cognito User Pool'));
51+
}
52+
53+
if (
54+
authResourcesConfig &&
55+
authResourcesConfig.Cognito?.identityPoolEndpoint
56+
) {
57+
logger.warn(
58+
getCustomEndpointWarningMessage('Amazon Cognito Identity Pool'),
59+
);
60+
}
4461
}
4562

4663
/**
@@ -106,3 +123,6 @@ export class AuthClass {
106123
);
107124
}
108125
}
126+
127+
const getCustomEndpointWarningMessage = (target: string): string =>
128+
`You are using a custom Amazon ${target} endpoint, ensure the endpoint is correct.`;

packages/core/src/singleton/Auth/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,9 @@ export interface AuthIdentityPoolConfig {
135135

136136
export interface CognitoIdentityPoolConfig {
137137
identityPoolId: string;
138+
/**
139+
* Use this field to specify a custom endpoint for the Amazon Cognito identity pool. Ensure this endpoint is correct and valid.
140+
*/
138141
identityPoolEndpoint?: string;
139142
allowGuestAccess?: boolean;
140143
}
@@ -152,6 +155,9 @@ export type CognitoUserPoolConfigMfaStatus = 'on' | 'off' | 'optional';
152155
export interface CognitoUserPoolConfig {
153156
userPoolClientId: string;
154157
userPoolId: string;
158+
/**
159+
* Use this field to specify a custom endpoint for the Amazon Cognito user pool. Ensure this endpoint is correct and valid.
160+
*/
155161
userPoolEndpoint?: string;
156162
signUpVerificationMethod?: 'code' | 'link';
157163
loginWith?: {

0 commit comments

Comments
 (0)