diff --git a/packages/auth/__tests__/auth-unit-test.ts b/packages/auth/__tests__/auth-unit-test.ts index 36767b4ec97..93789a8a305 100644 --- a/packages/auth/__tests__/auth-unit-test.ts +++ b/packages/auth/__tests__/auth-unit-test.ts @@ -3089,7 +3089,7 @@ describe('auth unit test', () => { spyon.mockClear(); }); - test('happy case with unverified', async () => { + test('happy case with verified', async () => { const spyon = jest .spyOn(Auth.prototype, 'userAttributes') .mockImplementationOnce(() => { @@ -3128,6 +3128,46 @@ describe('auth unit test', () => { spyon.mockClear(); }); + + test('happy case with verified as strings', async () => { + const spyon = jest + .spyOn(Auth.prototype, 'userAttributes') + .mockImplementationOnce(() => { + return new Promise((res: any, rej) => { + res([ + { + Name: 'email', + Value: 'email@amazon.com', + }, + { + Name: 'phone_number', + Value: '+12345678901', + }, + { + Name: 'email_verified', + Value: 'true', + }, + { + Name: 'phone_number_verified', + Value: 'True', + }, + ]); + }); + }); + + const auth = new Auth(authOptions); + const user = new CognitoUser({ + Username: 'username', + Pool: userPool, + }); + + expect(await auth.verifiedContact(user)).toEqual({ + unverified: {}, + verified: { email: 'email@amazon.com', phone_number: '+12345678901' }, + }); + + spyon.mockClear(); + }); }); describe('currentUserPoolUser test', () => { diff --git a/packages/auth/src/Auth.ts b/packages/auth/src/Auth.ts index e7e7c55e90f..1f05e8c2e68 100644 --- a/packages/auth/src/Auth.ts +++ b/packages/auth/src/Auth.ts @@ -2137,8 +2137,7 @@ export class AuthClass { attribute.Name === 'email_verified' || attribute.Name === 'phone_number_verified' ) { - obj[attribute.Name] = - attribute.Value === 'true' || attribute.Value === true; + obj[attribute.Name] = this.isTruthyString(attribute.Value) || attribute.Value === true; } else { obj[attribute.Name] = attribute.Value; } @@ -2147,6 +2146,10 @@ export class AuthClass { return obj; } + private isTruthyString(value: any): boolean { + return typeof value.toLowerCase === 'function' && value.toLowerCase() === 'true'; + } + private createCognitoUser(username: string): CognitoUser { const userData: ICognitoUserData = { Username: username,