How can I set and get cookies (server side) in Meteor?
There is no difference. A regular cookie can be set server side or client side. The 'classic' cookie will be sent back with each request. A cookie that is set by the server, will be sent to the client in a response.
Meteor methods are functions that are written on the server side, but can be called from the client side.
Cookies can be set or read server side, or client side.
An HTTP cookie (web cookie, browser cookie) is a small piece of data that a server sends to a user's web browser. The browser may store the cookie and send it back to the same server with later requests.
Meteor does not currently have a supported way to use cookies on the server.
You can use cookies on the client, though. Here's a snippet to show a splash screen the first time the user visits a page:
Meteor.startup(function () {
if (!document.cookie.match("splash="))
$('body').append(Meteor.ui.render(Template.splash));
});
Template.splash.events = {
'click .submit': function () {
document.cookie = "splash=ack;expires=Sat, 23 Mar 2013 00:00:0 GMT";
$('#splash_outer').remove();
}
};
You could use a similar approach and set the cookies in client side code, then send the results to the server in a method call.
It looks like we got a solution: ostrio/cookies which work both on the server side and on the client side: https://atmospherejs.com/ostrio/cookies
import { Cookies } from 'meteor/ostrio:cookies';
const cookies = new Cookies();
const oldValue = cookies.get("key");
cookies.set("key", "newValue");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With