Skip to content

redirect does not work when a cookie is used on resolve #1749

@carlosmfreitas2409

Description

@carlosmfreitas2409

What version of Elysia is running?

1.4.25

What platform is your computer?

Darwin 24.6.0 arm64 arm

What environment are you using

1.2.8

Are you using dynamic mode?

No

What steps can reproduce the bug?

When a route has a resolve that destructures the cookie, the redirect helper stops working. The endpoint returns a 200 response with an empty body instead of a 302 response containing the Location header.

Steps:

export const plugin = new Elysia()
	.guard({
		cookie: t.Cookie({
			sessionToken: t.Optional(t.String()),
		}),
	})
	.resolve({ as: 'global' }, ({ cookie }) => {
		const sessionToken = cookie?.sessionToken?.value;
		return { sessionToken };
	});

const app = new Elysia().use(plugin).get('/redirect', ({ redirect }) => {
	return redirect('https://google.com', 302); // <-- NOT WORKING
});

new Elysia().use(redirect).listen(3000);

What is the expected behavior?

The header must contain the Location and the redirect status code.

What do you see instead?

[200] /redirect
Headers:
content-length 0
date Fri, 20 Feb 2026 19:59:32 GMT

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

Yes

Metadata

Metadata

Assignees

No one assigned

    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