elysiajs / elysia

Ergonomic Framework for Humans

Home Page:https://elysiajs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`.guard` doesn't guard anymore with `cookie` (both `aot: true & false`)

bogeychan opened this issue · comments

What version of Elysia.JS is running?

1.1.4

What platform is your computer?

WSL Ubuntu

What steps can reproduce the bug?

// index.ts
import { Elysia, t } from "elysia";

const app = new Elysia()
  .guard({
    cookie: t.Cookie({ session: t.String() }),
  })
  .get("/", ({ cookie: { session } }) =>
    session.value ? session.value : "Empty"
  )
  .listen(5000);

let response = await app.handle(new Request(`${app.server!.url}`));
console.log(await response.text());

response = await app.handle(
  new Request(`${app.server!.url}`, { headers: { Cookie: "session=value" } })
);
console.log(await response.text());

app.stop();
bun run index.ts

What is the expected behavior?

Console output:

{
  "type": "validation",
  "on": "cookie",
  "property": "/session",
  "message": "Expected required property",
  "expected": {
    "session": ""
  },
  "found": {},
  "errors": [
    {
      "type": 45,
      "schema": {
        "type": "string"
      },
      "path": "/session",
      "message": "Expected required property"
    },
    {
      "type": 54,
      "schema": {
        "type": "string"
      },
      "path": "/session",
      "message": "Expected string"
    }
  ]
}
value

What do you see instead?

Console output:

Empty
value

Additional information

This used to work back in version 1.0.27


reported on discord

Not sure what happens but couldn't replicate on 1.1.7

Screenshot 2567-08-27 at 16 22 06 Screenshot 2567-08-27 at 16 21 57

Closing this as it is working again in the latest version