diff --git a/services/gunDB/contact-api/events/onReceivedReqs.js b/services/gunDB/contact-api/events/onReceivedReqs.js index b5f2ee07..4eb4ee61 100644 --- a/services/gunDB/contact-api/events/onReceivedReqs.js +++ b/services/gunDB/contact-api/events/onReceivedReqs.js @@ -112,6 +112,10 @@ const onReceivedReqs = cb => { cb(getReceivedReqs()) if (!subbed) { + const user = require('../../Mediator').getUser() + if (!user.is) { + logger.warn('Tried subscribing to onReceivedReqs without authing') + } require('./index').onCurrentHandshakeAddress(addr => { if (currentAddress === addr) { return @@ -128,7 +132,7 @@ const onReceivedReqs = cb => { .get(addr) .open(listenerForAddr(addr)) } - }, require('../../Mediator').getUser()) + }, user) Streams.onAvatar(react) Streams.onDisplayName(react) diff --git a/services/gunDB/contact-api/jobs/onAcceptedRequests.js b/services/gunDB/contact-api/jobs/onAcceptedRequests.js index 0c0dad80..3d3966a4 100644 --- a/services/gunDB/contact-api/jobs/onAcceptedRequests.js +++ b/services/gunDB/contact-api/jobs/onAcceptedRequests.js @@ -24,6 +24,7 @@ let procid = 0 */ const onAcceptedRequests = (user, SEA) => { if (!user.is) { + logger.warn('onAcceptedRequests() -> tried to sub without authing') throw new Error(ErrorCode.NOT_AUTH) } diff --git a/services/gunDB/contact-api/jobs/onOrders.js b/services/gunDB/contact-api/jobs/onOrders.js index 983ee485..47202384 100644 --- a/services/gunDB/contact-api/jobs/onOrders.js +++ b/services/gunDB/contact-api/jobs/onOrders.js @@ -26,6 +26,9 @@ let currentOrderAddr = '' * @returns {(order: ListenerData, orderID: string) => void} */ const listenerForAddr = (addr, user, SEA) => async (order, orderID) => { + if (!user.is) { + logger.warn('onOrders -> listenerForAddr() -> tried to sub without authing') + } try { if (addr !== currentOrderAddr) { return @@ -97,6 +100,7 @@ const listenerForAddr = (addr, user, SEA) => async (order, orderID) => { */ const onOrders = (user, gun, SEA) => { if (!user.is) { + logger.warn('onOrders() -> tried to sub without authing') throw new Error(ErrorCode.NOT_AUTH) } diff --git a/services/gunDB/contact-api/streams/lastSentReqID.js b/services/gunDB/contact-api/streams/lastSentReqID.js index 0c552922..01cce49d 100644 --- a/services/gunDB/contact-api/streams/lastSentReqID.js +++ b/services/gunDB/contact-api/streams/lastSentReqID.js @@ -1,4 +1,6 @@ /** @format */ +const logger = require('winston') + const Key = require('../key') /** @type {Record} */ @@ -18,22 +20,25 @@ const onLastSentReqIDs = cb => { cb() if (!subbed) { - require('../../Mediator') - .getUser() - .get(Key.USER_TO_LAST_REQUEST_SENT) - .open(data => { - if (typeof data === 'object' && data !== null) { - for (const [pub, id] of Object.entries(data)) { - if (typeof id === 'string' || id === null) { - pubToLastSentReqID[pub] = id - } - } - } else { - pubToLastSentReqID = {} - } + const user = require('../../Mediator').getUser() + if (!user.is) { + logger.warn('lastSentReqID() -> tried to sub without authing') + throw new Error('NOT_AUTH') + } - notify() - }) + user.get(Key.USER_TO_LAST_REQUEST_SENT).open(data => { + if (typeof data === 'object' && data !== null) { + for (const [pub, id] of Object.entries(data)) { + if (typeof id === 'string' || id === null) { + pubToLastSentReqID[pub] = id + } + } + } else { + pubToLastSentReqID = {} + } + + notify() + }) subbed = true } diff --git a/services/gunDB/contact-api/streams/pubToFeed.js b/services/gunDB/contact-api/streams/pubToFeed.js index 74d138bb..35f03d9d 100644 --- a/services/gunDB/contact-api/streams/pubToFeed.js +++ b/services/gunDB/contact-api/streams/pubToFeed.js @@ -137,6 +137,9 @@ const onOpenForPubFeedPair = ([pub, feed]) => pubToLastUpdate[pub] = thisUpdate const user = require('../../Mediator').getUser() + if (!user.is) { + logger.warn('pubToFeed -> onOpenForPubFeedPair() -> user is not auth') + } const SEA = require('../../Mediator').mySEA const ourSecret = await SEA.secret(await Utils.pubToEpub(pub), user._.sea) diff --git a/services/gunDB/contact-api/streams/pubToIncoming.js b/services/gunDB/contact-api/streams/pubToIncoming.js index ae2c5a28..e1ca1263 100644 --- a/services/gunDB/contact-api/streams/pubToIncoming.js +++ b/services/gunDB/contact-api/streams/pubToIncoming.js @@ -82,6 +82,9 @@ const onPubToIncoming = cb => { if (!subbed) { const user = require('../../Mediator').getUser() + if (!user.is) { + logger.warn(`subscribing to pubToIncoming on a unauth user`) + } user.get(USER_TO_INCOMING).open(onOpen) subbed = true } diff --git a/src/routes.js b/src/routes.js index fa4cc87e..e1d87228 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1594,6 +1594,7 @@ module.exports = async ( // spinup Events.onSimplerSentRequests(() => {})() const data = Events.getCurrentSentReqs() + logger.info(`Sent requests poll: ${JSON.stringify(data, null, 4)}`) res.json({ data, }) @@ -1611,6 +1612,7 @@ module.exports = async ( // spinup Events.onChats(() => {})() const data = Events.getChats() + logger.info(`Chats polled: ${JSON.stringify(data, null, 4)}`) res.json({ data })