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

Accessing a c.query variable removes c.cookie. #622

Open
techboy-coder opened this issue Apr 25, 2024 · 1 comment
Open

Accessing a c.query variable removes c.cookie. #622

techboy-coder opened this issue Apr 25, 2024 · 1 comment
Labels
bug Something isn't working pending Should be resolved in next release

Comments

@techboy-coder
Copy link

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

@techboy-coder techboy-coder added the bug Something isn't working label Apr 25, 2024
@techboy-coder techboy-coder changed the title Accessing a query variable removes c.cookie. Accessing a c.query variable removes c.cookie. Apr 25, 2024
@SaltyAom
Copy link
Member

SaltyAom commented May 2, 2024

This should have been fixed in 1.0.15, please update and let me know.

@SaltyAom SaltyAom added the pending Should be resolved in next release label May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working pending Should be resolved in next release
Projects
None yet
Development

No branches or pull requests

2 participants