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

Able to set client cookie from server generated cookie? #17

Closed
Ajaay opened this issue May 21, 2020 · 11 comments
Closed

Able to set client cookie from server generated cookie? #17

Ajaay opened this issue May 21, 2020 · 11 comments
Labels

Comments

@Ajaay
Copy link

Ajaay commented May 21, 2020

Hi,

I am generating cookies with AWS on the Accounts.Login hook on the server, and want to be able to then set these cookies on the client.

Is this possible with this package?

I've followed both documented example setups, but I'm not able to retrieve them on the client after they've been set on the server.

I see there is a 'send' method to forward cookies from client to server, but I really need to reverse of this.

Thanks!

@dr-dimitru
Copy link
Member

@Ajaay you can use .send() method to synchronize server and client cookies.
Use opts.onCookies hook for this purpose, note: cookies on the server are stateless

@Ajaay
Copy link
Author

Ajaay commented May 21, 2020 via email

@dr-dimitru
Copy link
Member

@Ajaay yes, just set new cookies on this hook, and it will be delivered to the Client.
Let me know if you will have any issues with it

@Ajaay
Copy link
Author

Ajaay commented May 21, 2020 via email

@dr-dimitru
Copy link
Member

Maybe you should use pub/sub to reactively send data to the user once data received from AWS?

You don't have to use "real" MongoDB collection, see "counts" example in Meteor's docs

@Ajaay
Copy link
Author

Ajaay commented May 22, 2020

Ok yeh that looks like it could do it - great shout thanks.

Just working through the send - onCookies hook and I've managed to get something set in the client. What I'm seeing though is that if I try to set more than one cookie, only the last set call finds it's way to the client. For example:

const cookie = new Cookies({
  auto: true,
  onCookies(cookies) {
    cookies.set('CloudFront-Key-Pair-Id', CloudFrontKeyPairId.value, options);
    cookies.set('CloudFront-Policy', CloudFrontPolicy.value, options);
    cookies.set('CloudFront-Signature', CloudFrontSignature.value, options);
  }
});

Only CloudFront-Signature ends up on the client. I've checked it's not an issue with what I'm setting in the others because commenting any of them out, it's always the last one that gets set..

Trying to work my way through the source code to figure out why this might be but struggling at the moment..

Any ideas?

Thanks for your help!

@dr-dimitru dr-dimitru added the bug label May 22, 2020
@dr-dimitru
Copy link
Member

@Ajaay thank you for reporting about this, labelled as "maybe" [bug]
Going to test it

@Ajaay
Copy link
Author

Ajaay commented May 23, 2020

@dr-dimitru My current theory is that it's because we're using this.response.setHeader in the set method, which will only allow us to set a single cookie. Perhaps we can create a valid cookieString for each of this.cookies and then use this.response.writeHead to send them all at once?

@Ajaay
Copy link
Author

Ajaay commented May 27, 2020

@dr-dimitru Found something interesting while trying to troubleshoot this today... If I browse directly to http://localhost:3000/__cookie__/set , all 3 cookies appear in the browser.

I'm doing some packet captures on my machine to dig into the HTTP headers but at the moment I can't spot any difference between what is being sent and received from the 'send' method, and then when browsing direct...

It's a strange one.

@dr-dimitru
Copy link
Member

Hello @Ajaay I'm sorry it's been a while, have you solved this issue? How?

dr-dimitru added a commit that referenced this issue Oct 7, 2020
- 🤝Compatibility with `meteor@1.11.1`;
- 🐞 Fix: #17 — set multiple cookies on the server; Thanks to @Ajaay
for submitting this issue;
- 📋 Minor documentation enhancements;
- 📦 Internal meteor dependencies upgrade.
@dr-dimitru
Copy link
Member

Hello @Ajaay ,

Thank you for submitting this issue! Bug was successfully fixed in v2.6.1.
Please, upgrade and let me know if issue is fixed on your end.

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

No branches or pull requests

2 participants