elysiajs / elysia

Ergonomic Framework for Humans
https://elysiajs.com
MIT License
10.59k stars 226 forks source link

Cookie sign doesn't work #833

Open bogeychan opened 2 months ago

bogeychan commented 2 months ago

What version of Elysia is running?

1.1.13

What platform is your computer?

WSL Ubuntu

What steps can reproduce the bug?

import { Elysia, t } from "elysia";

new Elysia({
  aot: false,
  cookie: { // both constructor secret and cookie schema (see below) doesn't work
    secrets: "Fischl von Luftschloss Narfidort",
    sign: ["profile"],
  },
})
  .get(
    "/",
    ({ cookie: { profile } }) => {
      profile.value = {
        id: 617,
        name: "Summoning 101",
      };
    },
    {
      cookie: t.Cookie(
        {
          profile: t.Optional(
            t.Object({
              id: t.Numeric(),
              name: t.String(),
            })
          ),
        }
        // {
        //   secrets: "Fischl von Luftschloss Narfidort",
        //   sign: ["profile"],
        // }
      ),
    }
  )
  .listen(8080);

GET http://localhost:8080/

What is the expected behavior?

signed cookie

What do you see instead?

image

%7B%22id%22%3A617%2C%22name%22%3A%22Summoning%20101%22%7D -> '{"id":617,"name":"Summoning 101"}'

Additional information

I assume this doesn't work with aot: true and false, its kinda blocked by https://github.com/elysiajs/elysia/issues/832


reported on discord

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

yes

Huliiiiii commented 1 month ago

I found that the cookie schema does not inherit global settings. When I remove the cookie schema, the global settings work properly. Is this the expected behavior?