How to set and retrieve cookies in Shopify express backend?

Topic summary

Goal: persist a cookie for ~3 weeks in a Shopify Express backend so users can access a third‑party API without logging in each session.

Approach shown: define a route to set a signed, httpOnly cookie with sameSite=strict and a long maxAge, then a route to read it via req.signedCookies or req.cookies.

Problem: both req.signedCookies and req.cookies return null even after calling the set‑cookie route.

Key question: what is missing in this setup to make the cookie persist and be readable across sessions?

Recency: a later commenter (two years after) asks whether a solution was found, indicating ongoing relevance and no posted fix.

Status: unresolved; no confirmed answer or action items. The included code snippet is central to understanding the issue.

Summarized with AI on December 30. AI used: gpt-5.

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!

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