Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Mudbill opened this issue Jan 7, 2024 · 3 comments · Fixed by silverlyra/elysia-jwt#1
Open

Comments

@Mudbill
Copy link

Mudbill commented Jan 7, 2024

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
Copy link

@Mudbill Stuck on same issue here

@jonasfroeller
Copy link

You could pass the array/object as a string 💀

@Mudbill
Copy link
Author

Mudbill commented Mar 4, 2024

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
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants