Skip to content

Regression in 1.3.6 (still in 1.3.8) that breaks @elysiajs/jwt with schema validation #1337

@JoeyEamigh

Description

@JoeyEamigh

What version of Elysia is running?

1.3.8

What platform is your computer?

(Arch) Linux 6.15.9-arch1-1 x86_64 unknown

What steps can reproduce the bug?

It appears that the setting of additionalProperties: false in 3dbb73a breaks @elysiajs/jwt. For some reason, the resulting schema rejects any additional properties in my custom schema beyond the base JWT fields Elysia expects.

To reproduce:

const baseJwtSchema = t.Object({
  id: t.String(),
  sessionId: t.String(),
  roles: t.Array(t.Enum(Role)),
  verification: t.String(),
});
const accessJwtSchema = t.Composite([
  baseJwtSchema,
  t.Object({
    firstName: t.String(),
    lastName: t.String(),
    email: t.String(),
    phone: t.Optional(t.String()),
    company: t.Optional(t.String()),
  }),
]);
const jwtSchema = t.Union([baseJwtSchema, accessJwtSchema]);

const authJwtPlugin = new Elysia({ name: 'auth-jwt-plugin' }).use(
  jwt({ name: 'authJwt', secret: environment.jwt.secret, schema: jwtSchema }),
);

Then try to pass in a token to authJwt.verify() with either of the two schemas. Validation will fail.

What is the expected behavior?

This same schema to work as it did in 1.3.5.

What do you see instead?

It doesn't :)

Additional information

Let me know if you need more info. I would fix it myself but I am not confident of the knock-on effects (I don't want to cause a regression of #1281).

Have you try removing the node_modules and bun.lockb and try again yet?

yes

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions