diff --git a/.circleci/config.yml b/.circleci/config.yml index a7abd937a83..179c421f88e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1571,10 +1571,7 @@ releasable_branches: &releasable_branches only: - release - main - - ui-components/main - - 1.0-stable - - geo/main - - in-app-messaging/main + - next # List of test browsers that are always used in every E2E test. Tests that aren't expected to interact with browser APIs # should use `minimal_browser_list` to keep test execution time low. diff --git a/lerna.json b/lerna.json index bbe91304810..53bb03522cf 100644 --- a/lerna.json +++ b/lerna.json @@ -7,6 +7,9 @@ "command": { "run": { "private": false + }, + "bootstrap": { + "ignore": "@aws-amplify/xr" } } } diff --git a/package.json b/package.json index 064ed53f7b1..743f6e875a0 100644 --- a/package.json +++ b/package.json @@ -27,8 +27,6 @@ "publish:next": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=next --preid=next --exact --no-verify-access", "publish:release": "lerna publish --conventional-commits --yes --message 'chore(release): Publish [ci skip]' --no-verify-access", "publish:verdaccio": "lerna publish --no-push --canary minor --dist-tag=unstable --preid=unstable --exact --force-publish --yes --no-verify-access", - "publish:geo/main": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=geo --preid=geo --exact --no-verify-access", - "publish:in-app-messaging/main": "lerna publish --canary --force-publish \"*\" --yes --dist-tag=in-app-messaging --preid=in-app-messaging --exact --no-verify-access", "ts-coverage": "lerna run ts-coverage" }, "husky": { diff --git a/packages/auth/__tests__/auth-unit-test.ts b/packages/auth/__tests__/auth-unit-test.ts index 3bf64da2e36..ecafed17013 100644 --- a/packages/auth/__tests__/auth-unit-test.ts +++ b/packages/auth/__tests__/auth-unit-test.ts @@ -80,6 +80,7 @@ jest.mock('amazon-cognito-identity-js/lib/CognitoUserPool', () => { CognitoUserPool.prototype.getCurrentUser = () => { return { username: 'username', + attributes: { email: 'test@test.com' }, getSession: callback => { // throw 3; callback(null, { @@ -1332,6 +1333,34 @@ describe('auth unit test', () => { spyon.mockClear(); }); + test('happy case attributes are appended', async () => { + const spyon = jest + .spyOn(CognitoUser.prototype, 'sendMFACode') + .mockImplementationOnce((code, callback) => { + callback.onSuccess(session); + }); + const hubSpy = jest.spyOn(Hub, 'dispatch'); + const auth = new Auth(authOptions); + const user = new CognitoUser({ + Username: 'username', + Pool: userPool, + }); + const expectedUser = Object.assign(user, { email: 'test@test.com' }); + const result = await auth.confirmSignIn(user, 'code', null); + expect(result.attributes.email).toEqual('test@test.com'); + expect(hubSpy).toHaveBeenCalledWith( + 'auth', + { + data: expectedUser, + event: 'signIn', + message: 'A user username has been signed in', + }, + 'Auth', + Symbol.for('amplify_default') + ); + spyon.mockClear(); + }); + test('happy case clientMetadata default', async () => { const spyon = jest.spyOn(CognitoUser.prototype, 'sendMFACode'); const auth = new Auth(authOptionsWithClientMetadata); @@ -1378,6 +1407,39 @@ describe('auth unit test', () => { spyon.mockClear(); }); + test('currentUserPoolUser fails but hub event still dispatches', async () => { + const auth = new Auth(authOptions); + const spyon = jest + .spyOn(CognitoUser.prototype, 'sendMFACode') + .mockImplementationOnce((code, callback) => { + callback.onSuccess(session); + }); + + const spyon2 = jest + .spyOn(auth, 'currentUserPoolUser') + .mockImplementationOnce(() => { + return Promise.reject('Could not get current user.'); + }); + const hubSpy = jest.spyOn(Hub, 'dispatch'); + const user = new CognitoUser({ + Username: 'username', + Pool: userPool, + }); + const result = await auth.confirmSignIn(user, 'code', null); + expect(result).toEqual(user); + expect(hubSpy).toHaveBeenCalledWith( + 'auth', + { + data: user, + event: 'signIn', + message: 'A user username has been signed in', + }, + 'Auth', + Symbol.for('amplify_default') + ); + spyon.mockClear(); + }); + test('onFailure', async () => { const spyon = jest .spyOn(CognitoUser.prototype, 'sendMFACode') @@ -3031,7 +3093,7 @@ describe('auth unit test', () => { } catch (e) { expect(e).toEqual(new Error('Error')); } - + spyon.mockClear(); }); @@ -3050,7 +3112,7 @@ describe('auth unit test', () => { const spyon = jest.spyOn(CognitoUser.prototype, 'updateAttributes') .mockImplementationOnce((attrs, callback: any) => { callback(null, 'SUCCESS', codeDeliverDetailsResult); - }); + }); const auth = new Auth(authOptions); const user = new CognitoUser({ diff --git a/packages/auth/src/Auth.ts b/packages/auth/src/Auth.ts index 0ab4efc7a91..ef347a820bc 100644 --- a/packages/auth/src/Auth.ts +++ b/packages/auth/src/Auth.ts @@ -1183,7 +1183,12 @@ export class AuthClass { logger.debug('cannot get cognito credentials', e); } finally { that.user = user; - + try { + const currentUser = await this.currentUserPoolUser(); + user.attributes = currentUser.attributes; + } catch (e) { + logger.debug('cannot get updated Cognito User', e); + } dispatchAuthEvent( 'signIn', user, @@ -1428,7 +1433,6 @@ export class AuthClass { user.updateAttributes( attributeList, (err, result, details) => { - if (err) { dispatchAuthEvent('updateUserAttributes_failure', err, 'Failed to update attributes'); return reject(err); @@ -1447,8 +1451,8 @@ export class AuthClass { } private createUpdateAttributesResultList( - attributes: Record, - codeDeliveryDetailsList?: CodeDeliveryDetails [] + attributes: Record, + codeDeliveryDetailsList?: CodeDeliveryDetails[] ): Record { const attrs = {}; Object.keys(attributes).forEach(key => { diff --git a/packages/aws-amplify/package.json b/packages/aws-amplify/package.json index 4c7b8bd2820..732a8b62654 100644 --- a/packages/aws-amplify/package.json +++ b/packages/aws-amplify/package.json @@ -52,7 +52,7 @@ "@aws-amplify/predictions": "5.0.15", "@aws-amplify/pubsub": "5.0.15", "@aws-amplify/storage": "5.1.5", - "@aws-amplify/xr": "4.0.15", + "@aws-amplify/xr": "latest", "tslib": "^2.0.0" }, "jest": { diff --git a/packages/xr/package.json b/packages/xr/package.json index c71a5725536..098e30a3e45 100644 --- a/packages/xr/package.json +++ b/packages/xr/package.json @@ -1,6 +1,7 @@ { "name": "@aws-amplify/xr", "version": "4.0.15", + "private": true, "description": "XR category of aws-amplify", "main": "./lib/index.js", "module": "./lib-esm/index.js",