Skip to content

Commit bf68f2b

Browse files
committed
Lazy init of auth0-js library
Fix for #15
1 parent 62b1894 commit bf68f2b

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
3232
"test": "npm run lint && npm run jest"
3333
},
34-
"version": "0.4.0",
34+
"version": "0.4.1",
3535
"dependencies": {
3636
"auth0-js": "^6.8.4",
3737
"isomorphic-fetch": "^2.2.1",

src/services/user.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,22 @@ import { getApiResponsePayloadV3 } from '../utils/tc';
1010
import { getApiV2, getApiV3 } from './api';
1111

1212
let auth0;
13-
if (isomorphy.isClientSide()) {
14-
const Auth0 = require('auth0-js'); /* eslint-disable-line global-require */
15-
auth0 = new Auth0({
16-
domain: config.AUTH0.DOMAIN,
17-
clientID: config.AUTH0.CLIENT_ID,
18-
callbackOnLocationHash: true,
19-
sso: false,
20-
});
13+
14+
/**
15+
* Returns a new, or cached auth0 instance.
16+
* @return {Object} Auth0 object.
17+
*/
18+
function getAuth0() {
19+
if (!auth0 && isomorphy.isClientSide()) {
20+
const Auth0 = require('auth0-js'); /* eslint-disable-line global-require */
21+
auth0 = new Auth0({
22+
domain: config.AUTH0.DOMAIN,
23+
clientID: config.AUTH0.CLIENT_ID,
24+
callbackOnLocationHash: true,
25+
sso: false,
26+
});
27+
}
28+
return auth0;
2129
}
2230

2331
/**
@@ -258,7 +266,7 @@ class User {
258266
*/
259267
async linkExternalAccount(userId, provider, callbackUrl) {
260268
return new Promise((resolve, reject) => {
261-
auth0.signin(
269+
getAuth0().signin(
262270
{
263271
popup: true,
264272
connection: provider,

0 commit comments

Comments
 (0)