elysiajs / elysia-jwt

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

Type definition for payload doesn't allow complex data structures #20

Open Mudbill opened 8 months ago

Mudbill commented 8 months ago

As per the JWT specification, it is a valid format to use arrays and objects as embedded payloads in JWT, however the TypeScript definition only allows values of string | number. This should be loosened up a bit.

A valid JWT payload:

image image

These two lines specify the types as Record<string, string | number>. In particular, allowing arrays is important, for situations such as the example here.

Master-Y0da commented 6 months ago

@Mudbill Stuck on same issue here

jonasfroeller commented 6 months ago

You could pass the array/object as a string 💀

Mudbill commented 6 months ago

You could pass the array/object as a string 💀

You could, but why should you? You could pass numbers as strings, but it's rarely a good idea.

A better solution (for the time being) is to just force override the type.

const token = await context.jwt.sign({
  roles: ["admin"] as any
});