Description
What version of Elysia is running?
1.2.9
What platform is your computer?
Darwin 24.0.0 arm64 arm
What steps can reproduce the bug?
Steps to reproduce:
- Create a new Elysia instance with the JWT plugin and define a
schema
for the token payload. - Sign a token using
jwtAccessToken.sign(...)
. - Immediately call
jwtAccessToken.verify(...)
on the newly signed token. - Notice the result is
false
.
Code example:
import { Elysia } from 'elysia';
import { jwt } from '@elysiajs/jwt';
import { t } from 'elysia';
import dayjs from 'dayjs';
// Elysia setup
export const jwtService = new Elysia({ name: 'service.jwt' })
.use(
jwt({
name: 'jwt',
secret: process.env.APP_JWT_SECRET || '', // ensure it's not empty
exp: '6h',
schema: t.Object({
sub: t.String(),
iat: t.Number(),
}),
})
)
.decorate(({ jwt }) => ({ verify: async() => {
const accessToken = await jwt.sign({ sub: '123', iat: dayjs().unix() });
const verified = await jwt.verify(accessToken);
console.log('Verified result:', verified) // returns false if 'schema' is included
}}));
What is the expected behavior?
When I sign a token and verify it immediately, verify() should return the decoded payload instead of false.
What do you see instead?
The verification returns false whenever a schema is provided.
Additional information
- If I remove the schema property, verification works as expected.
- I have tried with different exp values and the result is the same.
Have you try removing the node_modules
and bun.lockb
and try again yet?
yes