I have been struggling with figuring out cookies since first starting work on our website. I finally figured them out though. On our server we use firebase sessions in an express app where they are initialized like so:
app.use(
session({
name: "myCookie",
store: new FirestoreStore({ dataset: firestore }),
secret: process.env.SESSION_SECRET as string,
resave: false,
proxy: true,
cookie: {
maxAge: 1000 * 60 * 60 * 24 * 365 * 10,
httpOnly: true,
secure: process.env.PROD == "true",
sameSite: 'lax',
domain: "mydomain.com"
},
saveUninitialized: false,
})
)
The settings for the cookie did not matter for our iOS application, but for our website we had several hurdles. To get it to work on the desktop website browsers and android we had to set the cookie to secure and httpOnly. However, for iOS mobile browsers the cookie was failing to set. The issue was because mobile browsers on iOS only use first-party cookies. I had to add a CNAME for our API server which was a subdomain of our website and direct API calls to that CNAME. Then, in our API had to specify the domain for the cookie (which you must do explicitly for sub domains to be allowed in the cookie). This resolved it.