elysia
elysia copied to clipboard
Accessing a c.query variable removes c.cookie.
What version of Elysia.JS is running?
Elysia v1.0.14
What platform is your computer?
Linux 6.7.9-200.fc39.x86_64 x86_64 unknown
What steps can reproduce the bug?
Description:
I found a really weird behavior where after posting to /login aka logging in and having an auth cookie, I wasn't able to access any query variables while trying to access the cookies. c.cookie is undefined if c.query.id is accessed. Maybe I'm missing out on something, but this looks like weird and incorrect behavior.
Example:
import { Elysia, t } from 'elysia';
import { jwt } from '@elysiajs/jwt';
import { swagger } from '@elysiajs/swagger';
const app = new Elysia({ name: 'Example' })
.use(
jwt({
name: 'jwt',
secret: 'secret'
})
)
.use(swagger())
.get(
'/',
async (c) => {
// const id = c.query.id; // -> uncommenting me will make c.cookie undefined
const cookie = c.cookie;
console.log('cookie', cookie);
return { abc: 'abc', cookie };
},
{
query: t.Object({
id: t.Optional(
t.String({
minLength: 21,
maxLength: 21
})
)
})
}
)
.post(
'/login',
async (c) => {
c.cookie.auth.set({
value: await c.jwt.sign({
random: 'random'
}),
httpOnly: true,
maxAge: 7 * 86400,
path: '/'
});
return { name: 'user' };
},
{
body: t.Object({
name: t.String(),
password: t.String()
}),
detail: {
tags: ['Auth'],
summary: 'Login'
}
}
)
.listen(3001);
What is the expected behavior?
I'd expect to have c.cookie not be undefined.
What do you see instead?
c.cookie is undefined if c.query.variable is accessed.
Additional information
No response
This should have been fixed in 1.0.15, please update and let me know.