Skip to content

Commit

Permalink
fix: make types more user friendly (#288)
Browse files Browse the repository at this point in the history
* fix: make types more user friendly

* chore: update pkg lock

* chore: add changeset
  • Loading branch information
awsluja authored and Abhishek Raj committed Sep 27, 2023
1 parent c57316e commit d5aba32
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 36 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-seals-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@aws-amplify/auth-construct-alpha': patch
---

Update types for verification settings.
12 changes: 6 additions & 6 deletions packages/auth-construct/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ export type BasicLoginOptions = {

// @public
export type EmailLogin = true | {
emailBody?: `${string}{####}${string}`;
emailStyle?: aws_cognito.VerificationEmailStyle.CODE;
emailSubject?: string;
verificationEmailStyle?: aws_cognito.VerificationEmailStyle.CODE;
verificationEmailBody?: `${string}{####}${string}`;
verificationEmailSubject?: string;
} | {
emailBody?: `${string}{##Verify Email##}${string}`;
emailStyle?: aws_cognito.VerificationEmailStyle.LINK;
emailSubject?: string;
verificationEmailStyle?: aws_cognito.VerificationEmailStyle.LINK;
verificationEmailBody?: `${string}{##Verify Email##}${string}`;
verificationEmailSubject?: string;
};

// @public
Expand Down
42 changes: 21 additions & 21 deletions packages/auth-construct/src/construct.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ void describe('Auth construct', () => {
new AmplifyAuth(stack, 'test', {
loginWith: {
email: {
emailBody: customEmailVerificationMessage,
emailStyle: VerificationEmailStyle.CODE,
emailSubject: customEmailVerificationSubject,
verificationEmailBody: customEmailVerificationMessage,
verificationEmailStyle: VerificationEmailStyle.CODE,
verificationEmailSubject: customEmailVerificationSubject,
},
},
});
Expand All @@ -177,9 +177,9 @@ void describe('Auth construct', () => {
new AmplifyAuth(stack, 'test', {
loginWith: {
email: {
emailBody: customEmailVerificationMessage,
emailStyle: VerificationEmailStyle.CODE,
emailSubject: customEmailVerificationSubject,
verificationEmailBody: customEmailVerificationMessage,
verificationEmailStyle: VerificationEmailStyle.CODE,
verificationEmailSubject: customEmailVerificationSubject,
},
phoneNumber: {
verificationMessage: smsVerificationMessage,
Expand Down Expand Up @@ -217,9 +217,9 @@ void describe('Auth construct', () => {
loginWith: {
email: {
// @ts-expect-error We know this is a compile error, but must have runtime validation as well.
emailBody: customEmailVerificationMessage,
emailStyle: VerificationEmailStyle.CODE,
emailSubject: customEmailVerificationSubject,
verificationEmailBody: customEmailVerificationMessage,
verificationEmailStyle: VerificationEmailStyle.CODE,
verificationEmailSubject: customEmailVerificationSubject,
},
},
};
Expand All @@ -228,9 +228,9 @@ void describe('Auth construct', () => {
props = {
loginWith: {
email: {
emailBody: validMessage,
emailStyle: VerificationEmailStyle.CODE,
emailSubject: customEmailVerificationSubject,
verificationEmailBody: validMessage,
verificationEmailStyle: VerificationEmailStyle.CODE,
verificationEmailSubject: customEmailVerificationSubject,
},
},
};
Expand All @@ -246,9 +246,9 @@ void describe('Auth construct', () => {
loginWith: {
email: {
// @ts-expect-error We expect this to be a compile error
emailBody: customEmailVerificationMessage,
emailStyle: VerificationEmailStyle.LINK,
emailSubject: customEmailVerificationSubject,
verificationEmailBody: customEmailVerificationMessage,
verificationEmailStyle: VerificationEmailStyle.LINK,
verificationEmailSubject: customEmailVerificationSubject,
},
},
};
Expand All @@ -257,9 +257,9 @@ void describe('Auth construct', () => {
props = {
loginWith: {
email: {
emailBody: validMessage,
emailStyle: VerificationEmailStyle.LINK,
emailSubject: customEmailVerificationSubject,
verificationEmailBody: validMessage,
verificationEmailStyle: VerificationEmailStyle.LINK,
verificationEmailSubject: customEmailVerificationSubject,
},
},
};
Expand All @@ -278,9 +278,9 @@ void describe('Auth construct', () => {
new AmplifyAuth(stack, 'test', {
loginWith: {
email: {
emailBody: customEmailVerificationMessage,
emailStyle: VerificationEmailStyle.LINK,
emailSubject: customEmailVerificationSubject,
verificationEmailBody: customEmailVerificationMessage,
verificationEmailStyle: VerificationEmailStyle.LINK,
verificationEmailSubject: customEmailVerificationSubject,
},
},
})
Expand Down
6 changes: 3 additions & 3 deletions packages/auth-construct/src/construct.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ export class AmplifyAuth
if (emailEnabled && typeof props.loginWith.email === 'object') {
const emailSettings = props.loginWith.email;
userVerificationSettings = {
emailBody: emailSettings.emailBody,
emailStyle: emailSettings.emailStyle,
emailSubject: emailSettings.emailSubject,
emailBody: emailSettings.verificationEmailBody,
emailStyle: emailSettings.verificationEmailStyle,
emailSubject: emailSettings.verificationEmailSubject,
};
}
if (phoneEnabled && typeof props.loginWith.phoneNumber === 'object') {
Expand Down
24 changes: 18 additions & 6 deletions packages/auth-construct/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,26 @@ import { AuthOutput } from '@aws-amplify/backend-output-schemas/auth';
export type EmailLogin =
| true
| {
emailBody?: `${string}{####}${string}`;
emailStyle?: cognito.VerificationEmailStyle.CODE;
emailSubject?: string;
/**
* The type of verification. Must be one of aws_cognito.VerificationEmailStyle.
*/
verificationEmailStyle?: cognito.VerificationEmailStyle.CODE;
/**
* When verificationEmailStyle is set to VerificationEmailStyle.CODE, the emailBody must contain the template {####} where the code will be inserted.
*/
verificationEmailBody?: `${string}{####}${string}`;
/**
* The verification email subject.
*/
verificationEmailSubject?: string;
}
| {
emailBody?: `${string}{##Verify Email##}${string}`;
emailStyle?: cognito.VerificationEmailStyle.LINK;
emailSubject?: string;
verificationEmailStyle?: cognito.VerificationEmailStyle.LINK;
/**
* When verificationEmailStyle is set to VerificationEmailStyle.LINK, the emailBody must contain the template {##Verify Email##} where the link will be inserted.
*/
verificationEmailBody?: `${string}{##Verify Email##}${string}`;
verificationEmailSubject?: string;
};
/**
* Phone number login options.
Expand Down

0 comments on commit d5aba32

Please sign in to comment.