Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guard references to window on module load #2057

Merged
merged 4 commits into from
Nov 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions build/lock.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* lock v11.31.0
*
* Author: Auth0 <[email protected]> (http://auth0.com)
* Date: 15/10/2021, 16:04:30
* Date: 22/10/2021, 13:23:25
* License: MIT
*
*//******/ (function(modules) { // webpackBootstrap
Expand Down Expand Up @@ -7468,10 +7468,12 @@ function registerLanguageDictionary(language, dictionary) {
languageDictionaries[language] = __WEBPACK_IMPORTED_MODULE_1_immutable___default.a.fromJS(dictionary);
}

__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_8__utils_cdn_utils__["b" /* preload */])({
method: 'registerLanguageDictionary',
cb: registerLanguageDictionary
});
if (typeof window !== 'undefined') {
__webpack_require__.i(__WEBPACK_IMPORTED_MODULE_8__utils_cdn_utils__["b" /* preload */])({
method: 'registerLanguageDictionary',
cb: registerLanguageDictionary
});
}

/***/ }),
/* 13 */
Expand Down Expand Up @@ -14744,7 +14746,7 @@ QuickAuthPane.propTypes = {
/* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_auth0_js__ = __webpack_require__(101);


if (!window.Auth0) {
if (typeof window !== 'undefined' && !window.Auth0) {
window.Auth0 = {};
}

Expand Down Expand Up @@ -20345,7 +20347,7 @@ var EscKeyDownHandler = function () {
return EscKeyDownHandler;
}();

var IPHONE = window.navigator && !!window.navigator.userAgent.match(/iPhone/i);
var IPHONE = typeof window !== 'undefined' && window.navigator && !!window.navigator.userAgent.match(/iPhone/i);

var Container = function (_React$Component) {
_inherits(Container, _React$Component);
Expand Down Expand Up @@ -20617,7 +20619,7 @@ Container.propTypes = {
};

// NOTE: detecting the file protocol is important for things like electron.
var isFileProtocol = window.window && window.location && window.location.protocol === 'file:';
var isFileProtocol = typeof window !== 'undefined' && window.window && window.location && window.location.protocol === 'file:';

var defaultProps = Container.defaultProps = {
autofocus: false,
Expand Down Expand Up @@ -25691,16 +25693,18 @@ Object.defineProperty(__webpack_exports__, "__esModule", { value: true });



if (typeof window.define == 'function' && window.define.amd) {
window.define('auth0Lock', function () {
return __WEBPACK_IMPORTED_MODULE_0__index__["a" /* default */];
});
window.define('auth0LockPasswordless', function () {
return __WEBPACK_IMPORTED_MODULE_1__passwordless__["a" /* default */];
});
} else if (window.window) {
window.Auth0Lock = __WEBPACK_IMPORTED_MODULE_0__index__["a" /* default */];
window.Auth0LockPasswordless = __WEBPACK_IMPORTED_MODULE_1__passwordless__["a" /* default */];
if (typeof window !== 'undefined') {
if (typeof window.define == 'function' && window.define.amd) {
window.define('auth0Lock', function () {
return __WEBPACK_IMPORTED_MODULE_0__index__["a" /* default */];
});
window.define('auth0LockPasswordless', function () {
return __WEBPACK_IMPORTED_MODULE_1__passwordless__["a" /* default */];
});
} else if (window.window) {
window.Auth0Lock = __WEBPACK_IMPORTED_MODULE_0__index__["a" /* default */];
window.Auth0LockPasswordless = __WEBPACK_IMPORTED_MODULE_1__passwordless__["a" /* default */];
}
}

/***/ }),
Expand Down Expand Up @@ -30299,13 +30303,16 @@ WelcomeMessage.propTypes = {
};

var cssBlurSupport = function () {
// Check stolen from Modernizr, see https://github.com/Modernizr/Modernizr/blob/29eab707f7a2fb261c8a9c538370e97eb1f86e25/feature-detects/css/filters.js
var isEdge = window.navigator && !!window.navigator.userAgent.match(/Edge/i);
if (typeof window.document === 'undefined' || isEdge) return false;
if (typeof window !== 'undefined') {
// Check stolen from Modernizr, see https://github.com/Modernizr/Modernizr/blob/29eab707f7a2fb261c8a9c538370e97eb1f86e25/feature-detects/css/filters.js
var isEdge = window.navigator && !!window.navigator.userAgent.match(/Edge/i);
if (typeof window.document === 'undefined' || isEdge) return false;

var el = window.document.createElement('div');
el.style.cssText = 'filter: blur(2px); -webkit-filter: blur(2px)';
return !!el.style.length && (window.document.documentMode === undefined || window.document.documentMode > 9);
var el = window.document.createElement('div');
el.style.cssText = 'filter: blur(2px); -webkit-filter: blur(2px)';

return !!el.style.length && (window.document.documentMode === undefined || window.document.documentMode > 9);
}
}();

var Background = function (_React$Component4) {
Expand Down
4 changes: 2 additions & 2 deletions build/lock.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/lock.min.js.map

Large diffs are not rendered by default.

22 changes: 12 additions & 10 deletions src/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,16 @@
import Auth0Lock from './index';
import Auth0LockPasswordless from './passwordless';

if (typeof window.define == 'function' && window.define.amd) {
window.define('auth0Lock', function() {
return Auth0Lock;
});
window.define('auth0LockPasswordless', function() {
return Auth0LockPasswordless;
});
} else if (window.window) {
window.Auth0Lock = Auth0Lock;
window.Auth0LockPasswordless = Auth0LockPasswordless;
if (typeof window !== 'undefined') {
if (typeof window.define == 'function' && window.define.amd) {
window.define('auth0Lock', function () {
return Auth0Lock;
});
window.define('auth0LockPasswordless', function () {
return Auth0LockPasswordless;
});
} else if (window.window) {
window.Auth0Lock = Auth0Lock;
window.Auth0LockPasswordless = Auth0LockPasswordless;
}
}
10 changes: 6 additions & 4 deletions src/i18n.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ function registerLanguageDictionary(language, dictionary) {
languageDictionaries[language] = Immutable.fromJS(dictionary);
}

preload({
method: 'registerLanguageDictionary',
cb: registerLanguageDictionary
});
if (typeof window !== 'undefined') {
lbalmaceda marked this conversation as resolved.
Show resolved Hide resolved
preload({
method: 'registerLanguageDictionary',
cb: registerLanguageDictionary
});
}
11 changes: 9 additions & 2 deletions src/ui/box/container.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ class EscKeyDownHandler {
}
}

const IPHONE = window.navigator && !!window.navigator.userAgent.match(/iPhone/i);
const IPHONE =
typeof window !== 'undefined' &&
window.navigator &&
!!window.navigator.userAgent.match(/iPhone/i);

export default class Container extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -288,7 +291,11 @@ Container.propTypes = {
};

// NOTE: detecting the file protocol is important for things like electron.
const isFileProtocol = window.window && window.location && window.location.protocol === 'file:';
const isFileProtocol =
typeof window !== 'undefined' &&
window.window &&
window.location &&
window.location.protocol === 'file:';

export const defaultProps = (Container.defaultProps = {
autofocus: false,
Expand Down
7 changes: 6 additions & 1 deletion src/ui/box/header.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,18 @@ WelcomeMessage.propTypes = {
name: PropTypes.string
};

const cssBlurSupport = (function() {
const cssBlurSupport = (function () {
if (typeof window === 'undefined') {
return;
}

// Check stolen from Modernizr, see https://github.com/Modernizr/Modernizr/blob/29eab707f7a2fb261c8a9c538370e97eb1f86e25/feature-detects/css/filters.js
const isEdge = window.navigator && !!window.navigator.userAgent.match(/Edge/i);
if (typeof window.document === 'undefined' || isEdge) return false;

const el = window.document.createElement('div');
el.style.cssText = 'filter: blur(2px); -webkit-filter: blur(2px)';

return (
!!el.style.length &&
(window.document.documentMode === undefined || window.document.documentMode > 9)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/cdn_utils.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Auth0 from 'auth0-js';

if (!window.Auth0) {
if (typeof window !== 'undefined' && !window.Auth0) {
window.Auth0 = {};
}

Expand All @@ -11,7 +11,7 @@ export function load(attrs) {

if (!cbs[method]) {
cbs[method] = [];
window.Auth0[method] = function(...args) {
window.Auth0[method] = function (...args) {
cbs[method] = cbs[method].filter(x => {
if (x.check(...args)) {
setTimeout(() => x.cb(null, ...args), 0);
Expand Down