throws when trying to use `.authorized()`
See original GitHub issueI’ve tried to reduce my code to this, hope it is understandable:
const hyperdb = require('hyperdb')
const findPeers = require('./lib/find-peers')
const onceAuthorized = (db, key, cb) => {
const check = () => {
db.authorized(key, (err, isAuthorized) => {
if (err) cb(err)
else if (isAuthorized === true) cb(null)
else db.once('append', check) // todo: correct event?
})
}
setImmediate(check)
}
const onReady = (db, name) => {
findPeers(db.discoveryKey, (peer) => {
const s = db.replicate({live: true})
s.pipe(peer).pipe(s)
})
db.put('names/' + db.local.key.toString('hex'), name, (err) => {})
const send = (content) => {
let key = content.slice(12).trim()
if (!validKey.test(key)) return null
key = Buffer.from(key, 'hex')
db.authorize(key, (err) => {})
}
// this crashes
onceAuthorized(db, db.local.key, (err) => {})
}
const openChat = (dir, key, name) => {
const db = hyperdb(dir, key, {
valueEncoding: 'json'
})
db.ready((err) => {
if (err) return null // todo
onReady(db, name)
})
}
On peer A, I’ve opened the hyperdb without a predefined key
.
On peer B, I’ve opened the hyperdb with db.key
from peer A as key
. As I can tell from my logging, I have piped the replication streams together already (not sure why, the callback should have been called later).
The db.authorized(db.local.key, cb)
call then throws with the following error:
/Users/j/web/hyper-chat-cli/node_modules/hyperdb/index.js:272
var feedKey = self.feeds[head.clock[j]].key
^
TypeError: Cannot read property 'key' of undefined
at /Users/j/web/hyper-chat-cli/node_modules/hyperdb/index.js:272:47
at onhead (/Users/j/web/hyper-chat-cli/node_modules/hyperdb/index.js:309:10)
at done (/Users/j/web/hyper-chat-cli/node_modules/hyperdb/index.js:800:5)
at /Users/j/web/hyper-chat-cli/node_modules/hyperdb/index.js:467:5
at /Users/j/web/hyper-chat-cli/node_modules/hypercore/index.js:134:15
at apply (/Users/j/web/hyper-chat-cli/node_modules/thunky/index.js:44:12)
at process._tickCallback (internal/process/next_tick.js:114:19)
Using Node v9.10.1
, hyperdb@3.0.0-1
.
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (8 by maintainers)
Top Results From Across the Web
c# - .NET exceptions I can throw for Not Authorized or Not ...
If I were to look at some code that caught an UnauthorizedAccessViolation I would think that an unauthorized access attempt had been made...
Read more >authorize() should now throw an exception · Issue #42 ...
I think that authorize name inflicts that an action is being done (eq "to authorize" - check and pass/hold) while can seems like...
Read more >Authorization-code/callback throw exception after login
asked a question. Hi, I have created app of OIDC with web App with 2F and its implemented in local machine and working...
Read more >throw - JavaScript - MDN Web Docs - Mozilla
Use the throw statement to throw an exception. When you throw an exception, expression specifies the value of the exception.
Read more >Authorization - Laravel - The PHP Framework For Web Artisans
If the action is not authorized or if no user is currently authenticated, Laravel will automatically throw an Illuminate\Auth\Access\AuthorizationException ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is this the right fix? (edit: nope)
Now released