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

Can't set cookie: {secure: 'auto'} in TypeScript #222

Closed
2 tasks done
abcfy2 opened this issue Nov 27, 2023 · 2 comments · Fixed by #223
Closed
2 tasks done

Can't set cookie: {secure: 'auto'} in TypeScript #222

abcfy2 opened this issue Nov 27, 2023 · 2 comments · Fixed by #223

Comments

@abcfy2
Copy link

abcfy2 commented Nov 27, 2023

Prerequisites

  • I have written a descriptive issue title
  • I have searched existing issues to ensure the bug has not already been reported

Fastify version

4.24.0

Plugin version

10.6.0

Node.js version

20

Operating system

Linux

Operating system version (i.e. 20.04, 11.3, 10)

Manjaro 22

Description

When I use in typescript:

fastify.register(cors, {credentials: true, origin: true})
      .register(fastifyCookie)
      .register(fastifySession, {
        secret: 'a secret with minimum length of 32 characters',
        cookie: {secure: 'auto'}
      })

Will build failed:

      TS2769: No overload matches this call.
  Overload 1 of 3, '(plugin: FastifyPluginCallback<FastifySessionOptions, RawServerDefault, FastifyTypeProviderDefault>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Type 'string' is not assignable to type 'boolean | undefined'.
  Overload 2 of 3, '(plugin: FastifyPluginAsync<FastifySessionOptions, RawServerDefault, FastifyTypeProviderDefault>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Argument of type 'FastifySession' is not assignable to parameter of type 'FastifyPluginAsync<FastifySessionOptions, RawServerDefault, FastifyTypeProviderDefault>'.
  Overload 3 of 3, '(plugin: FastifyPluginCallback<FastifySessionOptions, RawServerDefault, FastifyTypeProviderDefault> | FastifyPluginAsync<...> | Promise<...> | Promise<...>, opts?: FastifyRegisterOptions<...> | undefined): FastifyInstance<...> & PromiseLike<...>', gave the following error.
    Type 'string' is not assignable to type 'boolean | undefined'.

Steps to Reproduce

See above

Expected Behavior

secure - The boolean value of the Secure attribute. Set this option to false when communicating over an unencrypted (HTTP) connection. Value can be set to auto; in this case, the Secure attribute will be set to false for an HTTP request. In the case of HTTPS, it will be set to true. Defaults to true.

@abcfy2
Copy link
Author

abcfy2 commented Nov 27, 2023

Seems the wrong in

cookie?: SerializeOptions;

Should be:

cookie?: CookieSerializeOptions;

see: https://github.com/fastify/fastify-cookie/blob/0c7351cde700f7d213faed6305416131c460407d/types/plugin.d.ts#L137-L140

?

@gurgunday
Copy link
Member

#213 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants