How to set and retrieve cookies in Shopify express backend?

How to set and retrieve cookies in Shopify express backend?

dd_dev
Shopify Partner
2 0 0

I need to save a cookie that will last for 3 weeks on my Shopify server to allow users to access a third party API without providing their login credentials each session load. With the Shopify express backend framework, how do I dynamically set a cookie and then retrieve it in future sessions?

 

A general example of what I understood to be the correct cookie setting/retrieving process for Shopify:

 

app.get('/setCookie', async (req, res) => {
res.cookie('test-cookie', 'test-cookie-data', {
signed: true,
httpOnly: true,
sameSite: 'strict',
maxAge: 99999999999 // placeholder
});
});

app.get('/getCookie', async (req, res) => {
console.log(req.signedCookies['test-cookie']);
});

 

However, whenever I try to access req.signedCookies or req.cookies, I am returned a null object, even after calling the setCookies route. What am I missing?

Thanks!

Reply 1 (1)

Jonas_Whal3s
Shopify Partner
2 0 0

The thread is already two years old, but the question is still relevant. Did you find a solution back then?