cookies-next icon indicating copy to clipboard operation
cookies-next copied to clipboard

It does not allow to configure the cookie with the option httpOnly

Open EdinsonG opened this issue 1 year ago • 5 comments

When creating the cookie without the httpOnly option, it is created correctly, however, when adding the httpOnly option, I do not create it and it does not return any error

note: I am creating the cookies client side

setCookie(name, value, { secure: true, httpOnly: true });

EdinsonG avatar Aug 30 '23 16:08 EdinsonG

Hello. I think you call setCookie on client side.

You need to use this function with req, res setCookie(name, value, { secure: true, httpOnly: true, req, res });

andreizanik avatar Aug 31 '23 06:08 andreizanik

req and res are only for server-side, not client-side. Those don't exist on the client.

So, the question again is, how do we do this from the client side?

a11smiles avatar Oct 12 '23 02:10 a11smiles

Same problem here, on client side, using this

        const options: OptionsType = {
          httpOnly: true,
          path: '/',
          sameSite: true,
          secure: true,
        };
        setCookie(name, value, { ...options, maxAge: 100 });

The cookie is not created.

If I comment httpOnly: true,, the cookie is created

bcetienne avatar Oct 17 '23 21:10 bcetienne

Hello! As far as I know setting cookie with httponly flag on client side is not possible at all. You can do this only on the server. Here is the topic from stackoverflow.

greg2012201 avatar Oct 17 '23 21:10 greg2012201

So, the question again is, how do we do this from the client side?

It's impossible. This is standard behavior for all cookies You can see stackoverflow link above and this one

andreizanik avatar Oct 18 '23 08:10 andreizanik