disable reinstantiation
This commit is contained in:
parent
d68326af36
commit
918fcd935f
2 changed files with 7 additions and 30 deletions
|
|
@ -224,7 +224,6 @@ let user
|
||||||
/** @type {string|null} */
|
/** @type {string|null} */
|
||||||
let _currentAlias = null
|
let _currentAlias = null
|
||||||
/** @type {string|null} */
|
/** @type {string|null} */
|
||||||
let _currentPass = null
|
|
||||||
|
|
||||||
/** @type {string|null} */
|
/** @type {string|null} */
|
||||||
let mySec = null
|
let mySec = null
|
||||||
|
|
@ -361,7 +360,6 @@ const authenticate = async (alias, pass, __user) => {
|
||||||
mySec = await mySEA.secret(_user._.sea.epub, _user._.sea)
|
mySec = await mySEA.secret(_user._.sea.epub, _user._.sea)
|
||||||
|
|
||||||
_currentAlias = alias
|
_currentAlias = alias
|
||||||
_currentPass = await mySEA.encrypt(pass, mySec)
|
|
||||||
|
|
||||||
await new Promise(res => setTimeout(res, 5000))
|
await new Promise(res => setTimeout(res, 5000))
|
||||||
|
|
||||||
|
|
@ -433,30 +431,11 @@ const instantiateGun = () => {
|
||||||
|
|
||||||
instantiateGun()
|
instantiateGun()
|
||||||
|
|
||||||
const freshGun = async () => {
|
const freshGun = () => {
|
||||||
const _gun = /** @type {unknown} */ (new Gun({
|
return {
|
||||||
axe: false,
|
gun,
|
||||||
multicast: false,
|
user
|
||||||
peers: Config.PEERS
|
|
||||||
}))
|
|
||||||
|
|
||||||
const gun = /** @type {GUNNode} */ (_gun)
|
|
||||||
|
|
||||||
const user = gun.user()
|
|
||||||
|
|
||||||
if (!_currentAlias || !_currentPass || !mySec) {
|
|
||||||
throw new Error('Called freshGun() without alias, pass and secret cached')
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const pass = await mySEA.decrypt(_currentPass, mySec)
|
|
||||||
|
|
||||||
if (typeof pass !== 'string') {
|
|
||||||
throw new Error('could not decrypt stored in memory current pass')
|
|
||||||
}
|
|
||||||
|
|
||||||
await authenticate(_currentAlias, pass, user)
|
|
||||||
|
|
||||||
return { gun, user }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -1428,9 +1407,7 @@ const register = async (alias, pass) => {
|
||||||
if (typeof ack.err === 'string') {
|
if (typeof ack.err === 'string') {
|
||||||
throw new Error(ack.err)
|
throw new Error(ack.err)
|
||||||
} else if (typeof ack.pub === 'string' || typeof user._.sea === 'object') {
|
} else if (typeof ack.pub === 'string' || typeof user._.sea === 'object') {
|
||||||
const mySecret = await mySEA.secret(user._.sea.epub, user._.sea)
|
// OK
|
||||||
_currentAlias = alias
|
|
||||||
_currentPass = await mySEA.encrypt(pass, mySecret)
|
|
||||||
} else {
|
} else {
|
||||||
throw new Error('unknown error, ack: ' + JSON.stringify(ack))
|
throw new Error('unknown error, ack: ' + JSON.stringify(ack))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -195,11 +195,11 @@ const tryAndWait = async (promGen, shouldRetry = () => false) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
`\n recreating a fresh gun and retrying one last time \n` +
|
`\n NOT recreating a fresh gun but retrying one last time \n` +
|
||||||
` args: ${promGen.toString()} -- ${shouldRetry.toString()}`
|
` args: ${promGen.toString()} -- ${shouldRetry.toString()}`
|
||||||
)
|
)
|
||||||
|
|
||||||
const { gun, user } = await require('../../Mediator/index').freshGun()
|
const { gun, user } = require('../../Mediator/index').freshGun()
|
||||||
|
|
||||||
return timeout10(promGen(gun, user))
|
return timeout10(promGen(gun, user))
|
||||||
/* eslint-enable no-empty */
|
/* eslint-enable no-empty */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue