Skip to content

Commit dfa138c

Browse files
committed
- fix LocalStorage namespace name when initializing the SDK with custom domain
1 parent 655de22 commit dfa138c

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

src/local-cache/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ export default class LocalCache {
99
constructor(app) {
1010
this.app = app
1111

12-
this.storageName = `${STORAGE_KEY_NAMESPACE}_${this.app.appId}`
12+
this.storageName = this.app.appId
13+
? `${STORAGE_KEY_NAMESPACE}_${this.app.appId}`
14+
: STORAGE_KEY_NAMESPACE
1315

1416
const Storage = Utils.isLocalStorageSupported
1517
? LocalStorage

test/unit/specs/local-cache/browser.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,22 @@ describe('<LocalCache> Browser', function() {
2929
delete global.localStorage
3030
})
3131

32-
it('has default storage name', () => {
32+
it('has default storage name with app id', () => {
3333
expect(Backendless.LocalCache.storageName).to.be.equal(`Backendless_${APP_ID}`)
34+
35+
Backendless.LocalCache.set('foo', 'bar')
36+
37+
expect(JSON.stringify(global.localStorage)).to.be.equal(`{"Backendless_${APP_ID}":"{\\"foo\\":\\"bar\\"}"}`)
38+
})
39+
40+
it('has default storage name without app id', () => {
41+
Backendless.initApp('https://foo.bar')
42+
43+
expect(Backendless.LocalCache.storageName).to.be.equal('Backendless')
44+
45+
Backendless.LocalCache.set('foo', 'bar')
46+
47+
expect(JSON.stringify(global.localStorage)).to.be.equal('{"Backendless":"{\\"foo\\":\\"bar\\"}"}')
3448
})
3549

3650
it('should migrate legacy storage', () => {

0 commit comments

Comments
 (0)