worker not returning jwt payload
I am trying to use
josejose library to verify jwt in workers but it seems like I am just getting a 200 without any data in the response. I am unsure what's going on. parsedJwt.payloadparsedJwt.payload is serializable and it should go in the error catch block if it errors out. So I am unsure why am I not getting any data in the response but the status code is set correctly to 200import { parse } from 'cookie';
import {jwtVerify, createLocalJWKSet} from 'jose';
interface Env {
USERFILES: R2Bucket;
}
export default {
async fetch(request, env): Promise<Response> {
const AUTH_COOKIE_NAME = 'user_jwt';
// this is the public keyset
const JWKS = createLocalJWKSet({
keys: [
{
kty: "EC",
use: "sig",
alg: "ES256",
kid: "",
crv: "P-256",
x: "",
y: ""
}
],
})
const url = new URL(request.url);
const key = url.pathname.slice(1);
const cookie = parse(request.headers.get("Cookie") || "");
if (cookie[AUTH_COOKIE_NAME] != null) {
const token = cookie[AUTH_COOKIE_NAME]
try {
const parsedJwt = await jwtVerify(token, JWKS) // verify sig and exp
// This is returning 200 with no response at all
return new Response(JSON.stringify(parsedJwt.payload), {status: 200});
} catch {
return new Response("counld not verify", {status: 403});
}
}
return new Response("Sorry, you have supplied an invalid key.", {
status: 403,
});
},
} satisfies ExportedHandler<Env>;import { parse } from 'cookie';
import {jwtVerify, createLocalJWKSet} from 'jose';
interface Env {
USERFILES: R2Bucket;
}
export default {
async fetch(request, env): Promise<Response> {
const AUTH_COOKIE_NAME = 'user_jwt';
// this is the public keyset
const JWKS = createLocalJWKSet({
keys: [
{
kty: "EC",
use: "sig",
alg: "ES256",
kid: "",
crv: "P-256",
x: "",
y: ""
}
],
})
const url = new URL(request.url);
const key = url.pathname.slice(1);
const cookie = parse(request.headers.get("Cookie") || "");
if (cookie[AUTH_COOKIE_NAME] != null) {
const token = cookie[AUTH_COOKIE_NAME]
try {
const parsedJwt = await jwtVerify(token, JWKS) // verify sig and exp
// This is returning 200 with no response at all
return new Response(JSON.stringify(parsedJwt.payload), {status: 200});
} catch {
return new Response("counld not verify", {status: 403});
}
}
return new Response("Sorry, you have supplied an invalid key.", {
status: 403,
});
},
} satisfies ExportedHandler<Env>;