leave.js 751 B

123456789101112131415161718192021
  1. const authPersist = require('./persist')
  2. const authsettings = require('./settings')
  3. //const { scope: seaIndexedDb } = require('./indexed')
  4. // This internal func executes logout actions
  5. const authLeave = async (gunRoot, alias = gunRoot._.user._.alias) => {
  6. var user = gunRoot._.user._ || {};
  7. [ 'get', 'soul', 'ack', 'put', 'is', 'alias', 'pub', 'epub', 'sea' ].map((key) => delete user[key])
  8. if(user.$){
  9. delete user.$.is;
  10. }
  11. // Let's use default
  12. gunRoot.user();
  13. // Removes persisted authentication & CryptoKeys
  14. try {
  15. await authPersist({ alias: alias })
  16. } catch (e) {} //eslint-disable-line no-empty
  17. return { ok: 0 }
  18. }
  19. module.exports = authLeave