worker not returning jwt payload

I am trying to use jose 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.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 200
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>;
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>;
1 Reply
ty
tyOP3mo ago
it's acting v.weird, if i manually thow an error in the try block, it gets caught in the catch block but again, no body in response but only status block. any clue what could be going on? OK. This is MAD. I am able to get the response when I use curl by using "copy request as curl" from browser network tab in firefox, but in the browser network response tab is empty let me try with chrome and see if its a ff issue
Want results from more Discord servers?
Add your server