From 5aad3a88189ecddce96ab462a0bf41f098f8f92c Mon Sep 17 00:00:00 2001 From: Daniel Lugo Date: Wed, 11 Dec 2019 13:02:58 -0400 Subject: [PATCH] add socket method for checking gun auth status --- services/gunDB/Mediator/index.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/services/gunDB/Mediator/index.js b/services/gunDB/Mediator/index.js index 1bc7de07..16a1bdc1 100644 --- a/services/gunDB/Mediator/index.js +++ b/services/gunDB/Mediator/index.js @@ -15,6 +15,9 @@ const mySEA = {} const $$__SHOCKWALLET__MSG__ = '$$__SHOCKWALLET__MSG__' const $$__SHOCKWALLET__ENCRYPTED__ = '$$_SHOCKWALLET__ENCRYPTED__' +// TO DO: Move this constant to common repo +const IS_GUN_AUTH = 'IS_GUN_AUTH' + mySEA.encrypt = (msg, secret) => { if (typeof msg !== 'string') { throw new TypeError('mySEA.encrypt() -> expected msg to be an string') @@ -288,6 +291,28 @@ class Mediator { socket.on(Event.ON_HANDSHAKE_ADDRESS, this.onHandshakeAddress) socket.on(Event.ON_RECEIVED_REQUESTS, this.onReceivedRequests) socket.on(Event.ON_SENT_REQUESTS, this.onSentRequests) + + socket.on(IS_GUN_AUTH, this.isGunAuth) + } + + isGunAuth = () => { + try { + const isGunAuth = isAuthenticated() + + this.socket.emit(IS_GUN_AUTH, { + ok: true, + msg: { + isGunAuth + }, + origBody: {} + }) + } catch (err) { + this.socket.emit(IS_GUN_AUTH, { + ok: false, + msg: err.message, + origBody: {} + }) + } } /**