Skip to content
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
24 changes: 14 additions & 10 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ const DEFAULT_PROPS = {

const STATELESS_PROPS = ['appId', 'apiKey', 'domain']

const root = (
(typeof self === 'object' && self.self === self && self) ||
(typeof global === 'object' && global.global === global && global)
)

const previousBackendless = root && root.Backendless
const previousBackendless = Utils.globalScope && Utils.globalScope.Backendless

const showLegacyDataWarning = () => {
if (!showLegacyDataWarning.isShown) {
Expand Down Expand Up @@ -173,6 +168,15 @@ class Backendless {
this.__appInfoPromise = new Promise((resolve, reject) => {
this.request.get({ url: this.urls.appInfo() })
.then(resolve)
.catch(error => {
if (error.code === 3064) {
this.setCurrentUserToken(null)

return this.request.get({ url: this.urls.appInfo() })
}

throw error
})
.catch(reject)
})
}
Expand Down Expand Up @@ -379,8 +383,8 @@ class Backendless {
}

noConflict() {
if (root) {
root.Backendless = previousBackendless
if (Utils.globalScope) {
Utils.globalScope.Backendless = previousBackendless
}

return this
Expand Down Expand Up @@ -572,8 +576,8 @@ class Backendless {

const backendless = new Backendless(DEFAULT_PROPS)

if (root) {
root.Backendless = backendless
if (Utils.globalScope) {
Utils.globalScope.Backendless = backendless
}

exports = module.exports = backendless
Expand Down
15 changes: 11 additions & 4 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const Utils = {

globalScope: (
(typeof self === 'object' && self.self === self && self) ||
(typeof global === 'object' && global.global === global && global)
(typeof global === 'object' && global.global === global && global) ||
(typeof globalThis === 'object' && globalThis)
),

castArray(value) {
Expand Down Expand Up @@ -66,9 +67,15 @@ const Utils = {
},

getWindowNavigator() {
return typeof __test_navigator !== 'undefined'
? __test_navigator
: global.navigator
if (typeof __test_navigator !== 'undefined') {
return __test_navigator
}

if (typeof navigator !== 'undefined') {
return navigator
}

return Utils.globalScope && Utils.globalScope.navigator
}
}

Expand Down
Loading