Skip to content

Commit

Permalink
Revert "[SDK-1379] Export constructor" (#382)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamjmcgrath authored Mar 19, 2020
1 parent 9dad76d commit 178b65f
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 61 deletions.
16 changes: 0 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,22 +67,6 @@ createAuth0Client({
}).then(auth0 => {
//...
});

//or, you can just instantiate the client on it's own
import { Auth0Client } from '@auth0/auth0-spa-js';
const auth0 = new Auth0Client({
domain: '<AUTH0_DOMAIN>',
client_id: '<AUTH0_CLIENT_ID>',
redirect_uri: '<MY_CALLBACK_URL>'
});
//if you do this, you'll need to check the session yourself
try {
await getTokenSilently();
} catch (error) {
if (error.error !== 'login_required') {
throw error;
}
}
```

### 1 - Login
Expand Down
11 changes: 4 additions & 7 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ jest.mock('../src/cache');
jest.mock('../src/transaction-manager');
jest.mock('../src/utils');

import createAuth0Client, { Auth0Client } from '../src/index';
import Auth0Client from '../src/Auth0Client';
import createAuth0Client from '../src/index';
import { AuthenticationError } from '../src/errors';
import version from '../src/version';
const GET_TOKEN_SILENTLY_LOCK_KEY = 'auth0.lock.getTokenSilently';
Expand Down Expand Up @@ -314,9 +315,7 @@ describe('Auth0', () => {
it('opens popup with correct popup, url and custom config', async () => {
const { auth0, utils } = await setup();
await auth0.loginWithPopup({}, { timeoutInSeconds: 1 });
expect(
utils.runPopup
).toHaveBeenCalledWith(
expect(utils.runPopup).toHaveBeenCalledWith(
`https://test.auth0.com/authorize?${TEST_QUERY_PARAMS}${TEST_TELEMETRY_QUERY_STRING}`,
{ timeoutInSeconds: 1 }
);
Expand All @@ -325,9 +324,7 @@ describe('Auth0', () => {
it('opens popup with correct popup, url and timeout from client options', async () => {
const { auth0, utils } = await setup({ authorizeTimeoutInSeconds: 1 });
await auth0.loginWithPopup({}, DEFAULT_POPUP_CONFIG_OPTIONS);
expect(
utils.runPopup
).toHaveBeenCalledWith(
expect(utils.runPopup).toHaveBeenCalledWith(
`https://test.auth0.com/authorize?${TEST_QUERY_PARAMS}${TEST_TELEMETRY_QUERY_STRING}`,
{ timeoutInSeconds: 1 }
);
Expand Down
19 changes: 0 additions & 19 deletions cypress/integration/initialisation.js

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"version": "1.6.4",
"main": "dist/lib/auth0-spa-js.cjs.js",
"types": "dist/typings/index.d.ts",
"browser": "dist/auth0-spa-js.production.js",
"module": "dist/auth0-spa-js.production.esm.js",
"scripts": {
"dev": "rimraf dist && rollup -c --watch",
Expand Down
12 changes: 4 additions & 8 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,13 @@ const getPlugins = shouldMinify => {
sourcemaps()
];
};
const footer = `('Auth0Client' in this) && this.console && this.console.warn && this.console.warn('Auth0Client already declared on the global namespace');
this && this.${EXPORT_NAME} && (this.Auth0Client = this.Auth0Client || this.${EXPORT_NAME}.Auth0Client);`;

let bundles = [
{
input: 'src/index.cjs.ts',
input: 'src/index.ts',
output: {
name: EXPORT_NAME,
file: 'dist/auth0-spa-js.development.js',
footer,
format: 'umd'
},
plugins: [
Expand All @@ -65,12 +62,11 @@ let bundles = [
if (isProduction) {
bundles = bundles.concat(
{
input: 'src/index.cjs.ts',
input: 'src/index.ts',
output: [
{
name: EXPORT_NAME,
file: 'dist/auth0-spa-js.production.js',
footer,
file: pkg.browser,
format: 'umd'
}
],
Expand All @@ -90,7 +86,7 @@ if (isProduction) {
plugins: getPlugins(isProduction)
},
{
input: 'src/index.cjs.ts',
input: 'src/index.ts',
output: [
{
name: EXPORT_NAME,
Expand Down
4 changes: 1 addition & 3 deletions src/Auth0Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {
runIframe,
sha256,
bufferToBase64UrlEncoded,
oauthToken,
validateCrypto
oauthToken
} from './utils';

import Cache from './cache';
Expand All @@ -36,7 +35,6 @@ export default class Auth0Client {
private readonly DEFAULT_SCOPE = 'openid profile email';

constructor(private options: Auth0ClientOptions) {
validateCrypto();
this.cache = new Cache();
this.transactionManager = new TransactionManager();
this.domainUrl = `https://${this.options.domain}`;
Expand Down
6 changes: 0 additions & 6 deletions src/index.cjs.ts

This file was deleted.

5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@ import * as ClientStorage from './storage';

//this is necessary to export the type definitions used in this file
import './global';
import { validateCrypto } from './utils';

export default async function createAuth0Client(options: Auth0ClientOptions) {
validateCrypto();

const auth0 = new Auth0Client(options);

if (!ClientStorage.get('auth0.is.authenticated')) {
Expand All @@ -31,5 +34,3 @@ export default async function createAuth0Client(options: Auth0ClientOptions) {
}
return auth0;
}

export { Auth0Client };

0 comments on commit 178b65f

Please sign in to comment.