Skip to content
This repository was archived by the owner on Aug 9, 2021. It is now read-only.

Commit dcbde39

Browse files
authored
Merge pull request #913 from 3box/fix/logout-state
Fix/logout state
2 parents 9aa9d3c + f35672c commit dcbde39

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

src/3box.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const localstorage = require('store')
21
const IPFS = require('ipfs')
32
const multiaddr = require('multiaddr')
43
const { createLink, validateLink } = require('3id-blockchain-utils')
@@ -48,6 +47,7 @@ class Box extends BoxApi {
4847
super()
4948
this._provider = provider
5049
this._ipfs = ipfs
50+
this._opts = opts
5151
this._serverUrl = opts.addressServer || ADDRESS_SERVER_URL
5252
/**
5353
* @property {KeyValueStore} public access the profile store of the users 3Box
@@ -560,10 +560,21 @@ class Box extends BoxApi {
560560
*/
561561
async logout () {
562562
if (!this._3id) throw new Error('logout: auth required')
563+
563564
await this.close()
564565
this._3id.logout()
565-
const address = await this._3id.getAddress()
566-
localstorage.remove('linkConsent_' + address)
566+
567+
delete this._3idEthAddress
568+
delete this.replicator
569+
delete this._3id
570+
571+
this.public = null
572+
this.private = null
573+
this.spaces = {}
574+
this.syncDone = null
575+
this.hasPublishedLink = {}
576+
577+
await this._init(this._opts)
567578
}
568579

569580
/**
@@ -573,6 +584,7 @@ class Box extends BoxApi {
573584
* @return {Boolean} true if the user is logged in
574585
*/
575586
static isLoggedIn (address) {
587+
console.warn('Box.isLoggedIn: function no longer supported, simply call auth and it will not prompt user again if they have already authenticated')
576588
return ThreeId.isLoggedIn(address)
577589
}
578590

src/3id/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ class ThreeId {
283283
}
284284

285285
logout () {
286+
this._rootDID = null
287+
this._subDIDs = {}
286288
localstorage.remove(STORAGE_KEY + this.managementAddress)
287289
this.stopUpdatePolling()
288290
}

src/__tests__/3box.test.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,13 @@ describe('3Box', () => {
435435
const box = await Box.openBox('0x12345', 'web3prov', boxOpts)
436436
await box.logout()
437437
expect(mocked3id.logoutFn).toHaveBeenCalledTimes(1)
438-
return box.close()
439438
})
440439

441440
it('should be logged out', async () => {
442441
const box = await Box.openBox('0x12345', 'web3prov', boxOpts)
443442
await box.logout()
444443
const isLoggedIn = Box.isLoggedIn('0xabcde')
445444
expect(isLoggedIn).toEqual(false)
446-
return box.close()
447445
})
448446

449447
it('should verify profiles correctly', async () => {

0 commit comments

Comments
 (0)