@1auth/messenger
Advanced tools
Comparing version 0.0.0-alpha.49 to 0.0.0-alpha.50
57
index.js
@@ -108,3 +108,3 @@ import { | ||
{}, | ||
{ messengers: [valueExists.id] } | ||
{ messengers: [{ id: valueExists.id }] } | ||
) | ||
@@ -167,3 +167,3 @@ return | ||
}, | ||
{ messengers: [sourceId] } | ||
{ messengers: [{ id: sourceId }] } | ||
) | ||
@@ -173,3 +173,14 @@ return id | ||
export const verifyToken = async (type, sub, token, notify = true) => { | ||
export const verifyToken = async (type, sub, token) => { | ||
let messengers = list(type, sub).then((items) => { | ||
const messengers = [] | ||
for (let i = items.length; i--;) { | ||
const messenger = items[i] | ||
if (!messenger.verify) { | ||
continue | ||
} | ||
messengers.push({ id: messenger.id }) | ||
} | ||
return messengers | ||
}) | ||
const { sourceId } = await authnVerify(options.token, sub, token) | ||
@@ -181,4 +192,7 @@ await options.store.update( | ||
) | ||
if (notify) { | ||
await options.notify.trigger(`messenger-${type}-create`, sub) | ||
messengers = await messengers | ||
if (messengers.length) { | ||
await options.notify.trigger(`messenger-${type}-create`, sub, undefined, { | ||
messengers | ||
}) | ||
} | ||
@@ -188,7 +202,9 @@ } | ||
export const remove = async (type, sub, id) => { | ||
const item = await options.store.select(options.table, { id, sub, type }, [ | ||
'verify' | ||
]) | ||
const messenger = await options.store.select( | ||
options.table, | ||
{ id, sub, type }, | ||
['value', 'verify'] | ||
) | ||
if (!item) { | ||
if (!messenger) { | ||
throw new Error('403 Unauthorized') | ||
@@ -203,5 +219,24 @@ } | ||
if (item?.verify) { | ||
await options.notify.trigger(`messenger-${type}-remove`, sub) | ||
// remove request is self clean up | ||
if (!messenger?.verify) { | ||
return | ||
} | ||
const { encryptionKey: encryptedKey } = messenger | ||
delete messenger.encryptionKey | ||
const { value } = symmetricDecryptFields( | ||
messenger, | ||
{ encryptedKey, sub }, | ||
options.encryptedFields | ||
) | ||
await Promise.all([ | ||
// Let messenger know it was removed | ||
options.notify.trigger(`messenger-${type}-remove-self`, sub, undefined, { | ||
messengers: [{ type, value }] | ||
}), | ||
// Let all others know one was removed | ||
options.notify.trigger(`messenger-${type}-remove`, sub) | ||
]) | ||
} | ||
@@ -208,0 +243,0 @@ |
{ | ||
"name": "@1auth/messenger", | ||
"version": "0.0.0-alpha.49", | ||
"version": "0.0.0-alpha.50", | ||
"description": "", | ||
@@ -53,5 +53,5 @@ "type": "module", | ||
"dependencies": { | ||
"@1auth/authn": "0.0.0-alpha.49", | ||
"@1auth/crypto": "0.0.0-alpha.49" | ||
"@1auth/authn": "0.0.0-alpha.50", | ||
"@1auth/crypto": "0.0.0-alpha.50" | ||
} | ||
} |
7312
234
+ Added@1auth/authn@0.0.0-alpha.50(transitive)
+ Added@1auth/crypto@0.0.0-alpha.50(transitive)
- Removed@1auth/authn@0.0.0-alpha.49(transitive)
- Removed@1auth/crypto@0.0.0-alpha.49(transitive)
Updated@1auth/authn@0.0.0-alpha.50
Updated@1auth/crypto@0.0.0-alpha.50