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

Commit

Permalink
Merge pull request #913 from 3box/fix/logout-state
Browse files Browse the repository at this point in the history
Fix/logout state
  • Loading branch information
zachferland authored Sep 14, 2020
2 parents 9aa9d3c + f35672c commit dcbde39
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
18 changes: 15 additions & 3 deletions src/3box.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const localstorage = require('store')
const IPFS = require('ipfs')
const multiaddr = require('multiaddr')
const { createLink, validateLink } = require('3id-blockchain-utils')
Expand Down Expand Up @@ -48,6 +47,7 @@ class Box extends BoxApi {
super()
this._provider = provider
this._ipfs = ipfs
this._opts = opts
this._serverUrl = opts.addressServer || ADDRESS_SERVER_URL
/**
* @property {KeyValueStore} public access the profile store of the users 3Box
Expand Down Expand Up @@ -560,10 +560,21 @@ class Box extends BoxApi {
*/
async logout () {
if (!this._3id) throw new Error('logout: auth required')

await this.close()
this._3id.logout()
const address = await this._3id.getAddress()
localstorage.remove('linkConsent_' + address)

delete this._3idEthAddress
delete this.replicator
delete this._3id

this.public = null
this.private = null
this.spaces = {}
this.syncDone = null
this.hasPublishedLink = {}

await this._init(this._opts)
}

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

Expand Down
2 changes: 2 additions & 0 deletions src/3id/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ class ThreeId {
}

logout () {
this._rootDID = null
this._subDIDs = {}
localstorage.remove(STORAGE_KEY + this.managementAddress)
this.stopUpdatePolling()
}
Expand Down
2 changes: 0 additions & 2 deletions src/__tests__/3box.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,15 +435,13 @@ describe('3Box', () => {
const box = await Box.openBox('0x12345', 'web3prov', boxOpts)
await box.logout()
expect(mocked3id.logoutFn).toHaveBeenCalledTimes(1)
return box.close()
})

it('should be logged out', async () => {
const box = await Box.openBox('0x12345', 'web3prov', boxOpts)
await box.logout()
const isLoggedIn = Box.isLoggedIn('0xabcde')
expect(isLoggedIn).toEqual(false)
return box.close()
})

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

0 comments on commit dcbde39

Please sign in to comment.