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,23 +622,57 @@ module.exports = async (
await Storage.set('trustedPKs', [...(trustedKeys || []), publicKey]) await Storage.set('trustedPKs', [...(trustedKeys || []), publicKey])
} }
// Send an event to update lightning's status const { lightning } = LightningServices.services
mySocketsEvents.emit('updateLightning')
// 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 //get the latest channel backups before subscribing
const user = require('../services/gunDB/Mediator').getUser() const user = require('../services/gunDB/Mediator').getUser()
const SEA = require('../services/gunDB/Mediator').mySEA const SEA = require('../services/gunDB/Mediator').mySEA
const { lightning } = LightningServices.services
await Common.Utils.makePromise((res, rej) => {
lightning.exportAllChannelBackups({}, (err, channelBackups) => { lightning.exportAllChannelBackups({}, (err, channelBackups) => {
if (err) { if (err) {
return handleError(res, err) return rej(new Error(err.details))
} }
res(
GunActions.saveChannelsBackup( GunActions.saveChannelsBackup(
JSON.stringify(channelBackups), JSON.stringify(channelBackups),
user, user,
SEA SEA
) )
)
}) })
})
// Send an event to update lightning's status
mySocketsEvents.emit('updateLightning')
//register to listen for channel backups //register to listen for channel backups
const onNewChannelBackup = () => { const onNewChannelBackup = () => {
@ -701,31 +735,11 @@ module.exports = async (
onNewChannelBackup() onNewChannelBackup()
startTipStatusJob() startTipStatusJob()
// Generate auth token and send it as a JSON response
const token = await auth.generateToken()
res.json({ res.json({
authorization: token, authorization: token,
user: { user: {
alias, alias,
publicKey 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)
}
}
)
})
} }
}) })