Skip to content

Commit

Permalink
Lazy init of auth0-js library
Browse files Browse the repository at this point in the history
Fix for #15
  • Loading branch information
birdofpreyru committed Jul 5, 2018
1 parent 62b1894 commit bf68f2b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"lint:js": "./node_modules/.bin/eslint --ext .js,.jsx .",
"test": "npm run lint && npm run jest"
},
"version": "0.4.0",
"version": "0.4.1",
"dependencies": {
"auth0-js": "^6.8.4",
"isomorphic-fetch": "^2.2.1",
Expand Down
26 changes: 17 additions & 9 deletions src/services/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,22 @@ import { getApiResponsePayloadV3 } from '../utils/tc';
import { getApiV2, getApiV3 } from './api';

let auth0;
if (isomorphy.isClientSide()) {
const Auth0 = require('auth0-js'); /* eslint-disable-line global-require */
auth0 = new Auth0({
domain: config.AUTH0.DOMAIN,
clientID: config.AUTH0.CLIENT_ID,
callbackOnLocationHash: true,
sso: false,
});

/**
* Returns a new, or cached auth0 instance.
* @return {Object} Auth0 object.
*/
function getAuth0() {
if (!auth0 && isomorphy.isClientSide()) {
const Auth0 = require('auth0-js'); /* eslint-disable-line global-require */
auth0 = new Auth0({
domain: config.AUTH0.DOMAIN,
clientID: config.AUTH0.CLIENT_ID,
callbackOnLocationHash: true,
sso: false,
});
}
return auth0;
}

/**
Expand Down Expand Up @@ -258,7 +266,7 @@ class User {
*/
async linkExternalAccount(userId, provider, callbackUrl) {
return new Promise((resolve, reject) => {
auth0.signin(
getAuth0().signin(
{
popup: true,
connection: provider,
Expand Down

0 comments on commit bf68f2b

Please sign in to comment.