Skip to content

Commit

Permalink
fix: Update Auth to import JS using named export (aws-amplify#10033)
Browse files Browse the repository at this point in the history
Imports specific functions instead of the whole JS module to improve bundle size
  • Loading branch information
jamesaucode authored Jun 29, 2022
1 parent fb1f02c commit 11b537c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
11 changes: 6 additions & 5 deletions packages/auth/__tests__/hosted-ui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ jest.mock('amazon-cognito-identity-js/lib/CognitoUser', () => {
return CognitoUser;
});

import { Hub, Credentials, StorageHelper, JS } from '@aws-amplify/core';
import * as AmplifyCore from '@aws-amplify/core';
const { Hub, Credentials, StorageHelper } = AmplifyCore;

const authOptionsWithOAuth: AuthOptions = {
userPoolId: 'awsUserPoolsId',
Expand Down Expand Up @@ -263,7 +264,7 @@ describe('Hosted UI tests', () => {
};
});

jest.spyOn(JS, 'browserOrNode').mockImplementation(() => ({
jest.spyOn(AmplifyCore, 'browserOrNode').mockImplementation(() => ({
isBrowser: true,
isNode: false,
}));
Expand Down Expand Up @@ -317,7 +318,7 @@ describe('Hosted UI tests', () => {
};
});

jest.spyOn(JS, 'browserOrNode').mockImplementation(() => ({
jest.spyOn(AmplifyCore, 'browserOrNode').mockImplementation(() => ({
isBrowser: false,
isNode: true,
}));
Expand Down Expand Up @@ -371,7 +372,7 @@ describe('Hosted UI tests', () => {
};
});

jest.spyOn(JS, 'browserOrNode').mockImplementation(() => ({
jest.spyOn(AmplifyCore, 'browserOrNode').mockImplementation(() => ({
isBrowser: false,
isNode: true,
}));
Expand Down Expand Up @@ -417,7 +418,7 @@ describe('Hosted UI tests', () => {
};
});

jest.spyOn(JS, 'browserOrNode').mockImplementation(() => ({
jest.spyOn(AmplifyCore, 'browserOrNode').mockImplementation(() => ({
isBrowser: true,
isNode: false,
}));
Expand Down
6 changes: 3 additions & 3 deletions packages/auth/src/Auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ import {
StorageHelper,
ICredentials,
Parser,
JS,
browserOrNode,
UniversalStorage,
urlSafeDecode,
} from '@aws-amplify/core';
Expand Down Expand Up @@ -1905,7 +1905,7 @@ export class AuthClass {
resolve: () => void,
reject: (reason?: any) => void
) {
const { isBrowser } = JS.browserOrNode();
const { isBrowser } = browserOrNode();

if (isBrowser) {
this.oAuthSignOutRedirectOrReject(reject);
Expand Down Expand Up @@ -2273,7 +2273,7 @@ export class AuthClass {
);

const currentUrl =
URL || (JS.browserOrNode().isBrowser ? window.location.href : '');
URL || (browserOrNode().isBrowser ? window.location.href : '');

const hasCodeOrError = !!(parse(currentUrl).query || '')
.split('&')
Expand Down
6 changes: 3 additions & 3 deletions packages/auth/src/urlListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
import { JS } from '@aws-amplify/core';
import { browserOrNode } from '@aws-amplify/core';

export default callback => {
if (JS.browserOrNode().isBrowser && window.location) {
if (browserOrNode().isBrowser && window.location) {
const url = window.location.href;

callback({ url });
} else if (JS.browserOrNode().isNode) {
} else if (browserOrNode().isNode) {
// continue building on ssr
() => {}; // noop
} else {
Expand Down

0 comments on commit 11b537c

Please sign in to comment.