diff --git a/examples/prompt/index.js b/examples/prompt/index.js index 6a7a738..48b8828 100644 --- a/examples/prompt/index.js +++ b/examples/prompt/index.js @@ -10,6 +10,9 @@ import { // Define the port to listen on const PORT = 3000; +// Cache for verification keys to improve performance +let verificationKeysCache = { id: "", keys: [] }; + // Define the handler function async function handler(request, response) { console.log(`Received [${request.method}] to [${request.url}]`); @@ -36,15 +39,18 @@ async function handler(request, response) { const keyID = String(request.headers["github-public-key-identifier"]); try { - const { isValidRequest, payload } = await verifyAndParseRequest( + const { isValidRequest, payload, cache } = await verifyAndParseRequest( body, signature, keyID, { token: tokenForUser, + cache: verificationKeysCache, }, ); + verificationKeysCache = cache; + if (!isValidRequest) { console.error("Request verification failed"); response.writeHead(401, { "Content-Type": "text/plain" });