Merge pull request #244 from shocknet/auth-bugs

Auth bugs
This commit is contained in:
Daniel Lugo 2020-11-06 13:17:02 -04:00 committed by GitHub
commit 877d319ff3

View file

@ -622,24 +622,58 @@ module.exports = async (
await Storage.set('trustedPKs', [...(trustedKeys || []), publicKey])
}
// Send an event to update lightning's status
mySocketsEvents.emit('updateLightning')
const { lightning } = LightningServices.services
// Generate auth token and send it as a JSON response
const token = await auth.generateToken()
// wait for wallet to warm up
await Common.Utils.makePromise((res, rej) => {
let tries = 0
let intervalID = null
intervalID = setInterval(() => {
if (tries === 3) {
rej(new Error(`Wallet did not warm up in under 3 seconds.`))
clearInterval(intervalID)
return
}
tries++
lightning.listInvoices({}, err => {
if (!err) {
clearInterval(intervalID)
res()
}
})
}, 1000)
})
//get the latest channel backups before subscribing
const user = require('../services/gunDB/Mediator').getUser()
const SEA = require('../services/gunDB/Mediator').mySEA
const { lightning } = LightningServices.services
lightning.exportAllChannelBackups({}, (err, channelBackups) => {
if (err) {
return handleError(res, err)
}
GunActions.saveChannelsBackup(
JSON.stringify(channelBackups),
user,
SEA
)
await Common.Utils.makePromise((res, rej) => {
lightning.exportAllChannelBackups({}, (err, channelBackups) => {
if (err) {
return rej(new Error(err.details))
}
res(
GunActions.saveChannelsBackup(
JSON.stringify(channelBackups),
user,
SEA
)
)
})
})
// Send an event to update lightning's status
mySocketsEvents.emit('updateLightning')
//register to listen for channel backups
const onNewChannelBackup = () => {
logger.warn('Subscribing to channel backup ...')
@ -701,31 +735,11 @@ module.exports = async (
onNewChannelBackup()
startTipStatusJob()
// Generate auth token and send it as a JSON response
const token = await auth.generateToken()
res.json({
authorization: token,
user: {
alias,
publicKey
},
follows: await GunGetters.Follows.currentFollows(),
data: {
invoices: await Common.makePromise((res, rej) => {
lightning.listInvoices(
{
reversed: true,
num_max_invoices: 50
},
(err, lres) => {
if (err) {
rej(new Error(err.details))
} else {
res(lres)
}
}
)
})
}
})