Skip to content

Commit

Permalink
Merge branch 'main' into circle-duplicate-package
Browse files Browse the repository at this point in the history
  • Loading branch information
amhinson authored May 4, 2021
2 parents cdd08d9 + 89a2250 commit 4e8c0cd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
42 changes: 41 additions & 1 deletion packages/auth/__tests__/auth-unit-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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', () => {
Expand Down
7 changes: 5 additions & 2 deletions packages/auth/src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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,
Expand Down

0 comments on commit 4e8c0cd

Please sign in to comment.