elysiajs / elysia-jwt

Plugin for Elysia for using JWT Authentication
MIT License
38 stars 16 forks source link

Header Parameter is stored in the payload instead of header #19

Open deanrih opened 8 months ago

deanrih commented 8 months ago

The Header Parameter config according to https://elysiajs.com/plugins/jwt.html#config is being stored in the payload section instead of header

for example, when doing

// setup.ts
export const JWT = jwt({
    name: "jwt",
    secret: "supersecret",
    typ: "JWT",
});

// main.ts
const jwtResult = await jwt.sign({
        sub: "subject",
});

will result in

eyJhbGciOiJIUzI1NiJ9.eyJ0eXAiOiJKV1QiLCJzdWIiOiJzdWJqZWN0In0.f69kq3ejRaV56IDJOAKDKHlejLU6_MiSiKsa5U4nTIs
{
  "alg": "HS256"
}
{
  "typ": "JWT",
  "sub": "subject"
}

instead of

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJzdWJqZWN0In0.aaT9AYvX_t5IExIkcUJ6Ux38zJcZ89-7q8SNlG5P9dM
{
  "alg": "HS256",
  "typ": "JWT"
}
{
  "sub": "subject"
}

looking at the code it seems there's no differentiation which is payload and which is header except the alg and crit

https://github.com/elysiajs/elysia-jwt/blob/188b20c92b53c427c087b1dc214ff8635ff046ff/src/index.ts#L136-L144