Skip to content

Commit 50821cd

Browse files
authored
Merge pull request #255 from Backendless/sandrosov/API-23/JS-SDK---problem-with-invalid-user-token-and-usage-of-global--master
API-23 - JS SDK - problem with invalid user token and usage of "global"
2 parents b530f74 + b3f3e04 commit 50821cd

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

src/index.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ const DEFAULT_PROPS = {
2121

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

24-
const root = (
25-
(typeof self === 'object' && self.self === self && self) ||
26-
(typeof global === 'object' && global.global === global && global)
27-
)
28-
29-
const previousBackendless = root && root.Backendless
24+
const previousBackendless = Utils.globalScope && Utils.globalScope.Backendless
3025

3126
const showLegacyDataWarning = () => {
3227
if (!showLegacyDataWarning.isShown) {
@@ -173,6 +168,15 @@ class Backendless {
173168
this.__appInfoPromise = new Promise((resolve, reject) => {
174169
this.request.get({ url: this.urls.appInfo() })
175170
.then(resolve)
171+
.catch(error => {
172+
if (error.code === 3064) {
173+
this.setCurrentUserToken(null)
174+
175+
return this.request.get({ url: this.urls.appInfo() })
176+
}
177+
178+
throw error
179+
})
176180
.catch(reject)
177181
})
178182
}
@@ -379,8 +383,8 @@ class Backendless {
379383
}
380384

381385
noConflict() {
382-
if (root) {
383-
root.Backendless = previousBackendless
386+
if (Utils.globalScope) {
387+
Utils.globalScope.Backendless = previousBackendless
384388
}
385389

386390
return this
@@ -572,8 +576,8 @@ class Backendless {
572576

573577
const backendless = new Backendless(DEFAULT_PROPS)
574578

575-
if (root) {
576-
root.Backendless = backendless
579+
if (Utils.globalScope) {
580+
Utils.globalScope.Backendless = backendless
577581
}
578582

579583
exports = module.exports = backendless

src/utils.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const Utils = {
66

77
globalScope: (
88
(typeof self === 'object' && self.self === self && self) ||
9-
(typeof global === 'object' && global.global === global && global)
9+
(typeof global === 'object' && global.global === global && global) ||
10+
(typeof globalThis === 'object' && globalThis)
1011
),
1112

1213
castArray(value) {
@@ -66,9 +67,15 @@ const Utils = {
6667
},
6768

6869
getWindowNavigator() {
69-
return typeof __test_navigator !== 'undefined'
70-
? __test_navigator
71-
: global.navigator
70+
if (typeof __test_navigator !== 'undefined') {
71+
return __test_navigator
72+
}
73+
74+
if (typeof navigator !== 'undefined') {
75+
return navigator
76+
}
77+
78+
return Utils.globalScope && Utils.globalScope.navigator
7279
}
7380
}
7481

0 commit comments

Comments
 (0)