Skip to content

Commit c35ec01

Browse files
committed
Improve token check query
1 parent c85059c commit c35ec01

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

functions/src/webhooks/transcription.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,25 @@ export const transcription = functions.https.onRequest(async (req, res) => {
2020
.where("videoAssemblyId", "==", transcript.id)
2121
.get()
2222
if (maybeEventInDb.docs.length) {
23-
const authenticatedEventsInDb = maybeEventInDb.docs.filter(e => {
24-
const hashedToken = sha256(
25-
String(req.headers["webhook_auth_header_value"])
26-
)
27-
return (
28-
hashedToken ===
29-
e.get("webhookAuth").data().videoAssemblyWebhookToken
30-
)
31-
})
23+
const authenticatedEventsInDb = maybeEventInDb.docs.filter(
24+
async e => {
25+
const hashedToken = sha256(
26+
String(req.headers["webhook_auth_header_value"])
27+
)
28+
29+
const tokenInDb = await db
30+
.collection("events")
31+
.doc(e.id)
32+
.collection("private")
33+
.doc("webhookAuth")
34+
.get()
35+
const tokenInDbData = tokenInDb.data()
36+
if (tokenInDbData) {
37+
return hashedToken === tokenInDbData.videoAssemblyWebhookToken
38+
}
39+
return false
40+
}
41+
)
3242
if (authenticatedEventsInDb) {
3343
try {
3444
await db

0 commit comments

Comments
 (0)