Monday, 28 October 2019

Express not setting Cookie

I have 2 servers. One hosting a next.js application on localhost:5555 and another hosting an express server for the api on localhost:4444.

The authentication api returns a cookie however this is not being set in the browser running on localhost:5555.

  res.cookie('cokkieName', 'bob', {
        domain: '127.0.0.1:5555',
        maxAge: 900000,
        httpOnly: true,
    });

    res.status(200).json({
        session: jwtSigned,
        role: 'default',
    });

My cors setup is:

const options: cors.CorsOptions = {
    allowedHeaders: ['Origin', 'X-Requested-With', 'Content-Type', 'Accept', 'X-Access-Token', 'Authorization'],
    credentials: true,
    methods: 'GET,HEAD,OPTIONS,PUT,PATCH,POST,DELETE',
    origin: 'http://localhost:5555',
    preflightContinue: false,
};

I'd prefer to set the cookie with the api rather than on the via next.js.

I've tried alternating the cors settings but have had no success. The client call uses axios and has withCredentials set.



from Express not setting Cookie

No comments:

Post a Comment