Skip to content

Commit abb4cb7

Browse files
authored
fix: auth name issue #2559 (#2605)
* fix(auth-construct): add userPoolName property to ensure consistent resource naming #2559 This fix ensures that the Cognito User Pool name is explicitly set to the same value as the construct ID, preventing inconsistency in resource naming between different AWS resources generated by the construct. * chore: add empty changeset for auth-construct fix * fix: use name parameter in userPoolName property of Cognito UserPool * fix: use CDK default naming for UserPool when name is not provided * fix: move userPoolName to getUserPoolProps function
1 parent 3423974 commit abb4cb7

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

.changeset/loud-teams-wink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/auth-construct': patch
3+
---
4+
5+
Modified the AmplifyAuth class in packages/auth-construct/src/construct.ts to explicitly set the userPoolName property to match the construct's name property

packages/auth-construct/src/construct.test.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { beforeEach, describe, it, mock } from 'node:test';
22
import { AmplifyAuth } from './construct.js';
33
import { App, SecretValue, Stack, aws_cognito } from 'aws-cdk-lib';
4-
import { Template } from 'aws-cdk-lib/assertions';
4+
import { Match, Template } from 'aws-cdk-lib/assertions';
55
import assert from 'node:assert';
66
import {
77
BackendOutputEntry,
@@ -3062,4 +3062,30 @@ void describe('Auth construct', () => {
30623062
assert.equal(name.startsWith(expectedPrefix), true);
30633063
});
30643064
});
3065+
3066+
void it('sets the correct userPoolName when name is provided', () => {
3067+
const app = new App();
3068+
const stack = new Stack(app);
3069+
const customAuthName = 'CustomAuthName';
3070+
new AmplifyAuth(stack, 'test', {
3071+
loginWith: { email: true },
3072+
name: customAuthName,
3073+
});
3074+
const template = Template.fromStack(stack);
3075+
template.hasResourceProperties('AWS::Cognito::UserPool', {
3076+
UserPoolName: customAuthName,
3077+
});
3078+
});
3079+
3080+
void it('uses empty string as userPoolName when name is not provided', () => {
3081+
const app = new App();
3082+
const stack = new Stack(app);
3083+
new AmplifyAuth(stack, 'test', {
3084+
loginWith: { email: true },
3085+
});
3086+
const template = Template.fromStack(stack);
3087+
template.hasResourceProperties('AWS::Cognito::UserPool', {
3088+
UserPoolName: Match.absent(),
3089+
});
3090+
});
30653091
});

packages/auth-construct/src/construct.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,7 @@ export class AmplifyAuth
630630
)
631631
: undefined,
632632
customSenderKmsKey: this.customSenderKMSkey,
633+
userPoolName: props.name || undefined,
633634
};
634635
return userPoolProps;
635636
};

0 commit comments

Comments
 (0)