Checks before validation

This commit is contained in:
Daniel Lugo 2021-12-26 15:41:37 -04:00
parent e0e6fc3173
commit 63a1b29d2d

View file

@ -511,10 +511,16 @@ module.exports = async (
try { try {
const health = await checkHealth() const health = await checkHealth()
const walletInitialized = await walletExists() const walletInitialized = await walletExists()
// If we're connected to lnd, unlock the wallet using the password supplied
// and generate an auth token if that operation was successful.
if (health.LNDStatus.success && walletInitialized) {
const { alias, password, invite, accessSecret } = req.body const { alias, password, invite, accessSecret } = req.body
const lndUp = health.LNDStatus.success
if (!lndUp) {
throw new Error(health.LNDStatus.message)
}
if (!walletInitialized) {
throw new Error('Please create a wallet before authenticating')
}
await recreateLnServices() await recreateLnServices()
@ -537,9 +543,9 @@ module.exports = async (
process.env.TRUSTED_KEYS === 'true' || !process.env.TRUSTED_KEYS process.env.TRUSTED_KEYS === 'true' || !process.env.TRUSTED_KEYS
const trustedKeys = await Storage.get('trustedPKs') const trustedKeys = await Storage.get('trustedPKs')
// Falls back to true if trusted keys is disabled in .env // Falls back to true if trusted keys is disabled in .env
const [isKeyTrusted = !trustedKeysEnabled] = ( const [isKeyTrusted = !trustedKeysEnabled] = (trustedKeys || []).filter(
trustedKeys || [] trustedKey => trustedKey === publicKey
).filter(trustedKey => trustedKey === publicKey) )
const walletUnlocked = health.LNDStatus.walletStatus === 'unlocked' const walletUnlocked = health.LNDStatus.walletStatus === 'unlocked'
const { authorization = '' } = req.headers const { authorization = '' } = req.headers
@ -721,26 +727,6 @@ module.exports = async (
publicKey publicKey
} }
}) })
return true
}
if (!walletInitialized) {
res.status(500).json({
field: 'wallet',
errorMessage: 'Please create a wallet before authenticating',
success: false
})
return false
}
res.status(500)
res.json({
field: 'health',
errorMessage: sanitizeLNDError(health.LNDStatus.message),
success: false
})
return false
} catch (err) { } catch (err) {
logger.error('Unlock Error:', err) logger.error('Unlock Error:', err)
res.status(400) res.status(400)