Skip to content

Commit f216e28

Browse files
update invite when type of invite changes
1 parent 1de9afa commit f216e28

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,10 @@ class Autopass extends ReadyResource {
253253
if (this.opened === false) await this.ready()
254254
const readOnly = opts?.readOnly ? true : false
255255
const existing = await this.base.view.findOne('@autopass/invite', {})
256-
if (existing) {
256+
257+
if (existing && existing.readOnly !== readOnly) {
258+
await this.deleteInvite()
259+
} else if (existing) {
257260
if (this.member) await this.member.flushed()
258261
return z32.encode(existing.invite)
259262
}

test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,26 @@ test('invites', async function (t) {
8181
})
8282
})
8383

84+
test('invite resets when createInvite type is different than previous', async function (t) {
85+
t.plan(1)
86+
87+
const tn = await testnet(10, t)
88+
89+
const a = await create(t, { bootstrap: tn.bootstrap })
90+
t.teardown(() => {
91+
a.close()
92+
})
93+
94+
const inv = await a.createInvite()
95+
const invReadOnly = await a.createInvite({ readOnly: true })
96+
97+
if (inv !== invReadOnly) {
98+
t.pass('invite is reset ')
99+
} else {
100+
t.fail()
101+
}
102+
})
103+
84104
test('blind encryption', async function (t) {
85105
t.plan(4)
86106

0 commit comments

Comments
 (0)