Monday 14 May 2018

Cannot set a cookie through express on Heroku

I have a react app and a nodejs server running both on the same heroku account under different subdomains;server.herokuapp.com reactapp.herokuapp.com I post username and password data to nodejs server through axios in react app.axios.post(`${server.url}/login`, {email, password}, {withCredentials: true}) In the nodejs server, I use express along with cors middleware.const origin = 'https://ift.tt/2wGqKiz' let app = express(); app.use(cors({credentials: true, origin: origin})); Nodejs server gets the data from the client (reactapp) and sends it to another remote server. The response from the remote server is a sessionid that I have to use to create a cookie with.loginOptions = {...some information for the remote server} app.post("/login", (req, res) => { request(loginOptions, (error, response, body) => loginCallback(res,error, response, body)) }) const loginCallback = (res, error, response, body) => { cookieData = setCookie.parse(response.caseless.dict['set-cookie'][0]); const {name, value} = cookieData[0]; res.cookie(name, value).send('CookieSet') } This just works fine on localhost.However, on Heroku, I cannot set the cookie. I get the sessionid and everything from the remote server in accordance with the username and password but setting the cookie is the problem.

Submitted May 14, 2018 at 02:20PM by eligloys

No comments:

Post a Comment