fix: verifyQstashHeader now returns false when SignatureError is thrown
This commit is contained in:
@@ -16,7 +16,6 @@ import { getUpcomingTitlesFromAnilist } from "./anilist";
|
|||||||
const app = new Hono();
|
const app = new Hono();
|
||||||
|
|
||||||
app.post("/titles", async (c) => {
|
app.post("/titles", async (c) => {
|
||||||
console.log(c.req.path);
|
|
||||||
if (
|
if (
|
||||||
!(await verifyQstashHeader(
|
!(await verifyQstashHeader(
|
||||||
env<Env, typeof c>(c, "workerd"),
|
env<Env, typeof c>(c, "workerd"),
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { Receiver } from "@upstash/qstash";
|
import { Receiver, SignatureError } from "@upstash/qstash";
|
||||||
|
|
||||||
import type { Env } from "~/types/env";
|
import type { Env } from "~/types/env";
|
||||||
|
|
||||||
export function verifyQstashHeader(
|
export async function verifyQstashHeader(
|
||||||
env: Env,
|
env: Env,
|
||||||
route: string,
|
route: string,
|
||||||
signature: string | undefined,
|
signature: string | undefined,
|
||||||
@@ -12,14 +12,22 @@ export function verifyQstashHeader(
|
|||||||
return Promise.resolve(false);
|
return Promise.resolve(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
const receiver = new Receiver({
|
try {
|
||||||
currentSigningKey: env.QSTASH_CURRENT_SIGNING_KEY,
|
const receiver = new Receiver({
|
||||||
nextSigningKey: env.QSTASH_NEXT_SIGNING_KEY,
|
currentSigningKey: env.QSTASH_CURRENT_SIGNING_KEY,
|
||||||
});
|
nextSigningKey: env.QSTASH_NEXT_SIGNING_KEY,
|
||||||
|
});
|
||||||
|
|
||||||
return receiver.verify({
|
return await receiver.verify({
|
||||||
body,
|
body,
|
||||||
signature,
|
signature,
|
||||||
url: `https://aniplay-v2.rururu.workers.dev${route}`,
|
url: `https://aniplay-v2.rururu.workers.dev${route}`,
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof SignatureError) {
|
||||||
|
return Promise.resolve(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user