Giter Site home page Giter Site logo

Comments (10)

ahmedyounes avatar ahmedyounes commented on April 27, 2024 3

I figured it out i think your issue will have the sample problem too ..
in proxy configuration make sure you are matching any path
with double ** not only *

const proxy = require("http-proxy-middleware");
module.exports = function(app) {
  app.use(proxy("/api/**", { // https://github.com/chimurai/http-proxy-middleware
    target: "http://localhost:5000",
    secure: false
  }));
};

from cookie-session.

cloudhary avatar cloudhary commented on April 27, 2024

Hey @Code-Crash, might this be of help?

from cookie-session.

Code-Crash avatar Code-Crash commented on April 27, 2024

@cloudhary , Thanks for the help. let me test it and will get back to you in some time.

from cookie-session.

ahmedyounes avatar ahmedyounes commented on April 27, 2024

@Code-Crash you are right , just noticed the same and its working with postman ... trying what @cloudhary introduced

from cookie-session.

unlucio avatar unlucio commented on April 27, 2024

@Code-Crash you need to pass {withCredentials: true} to axios:
axios[method](url, {withCredentials: true})

example:

axios.get('/test', {withCredentials: true}).then(console.log).catch(console.error);

otherwise axios is not going to carry the cookies with the request.

from cookie-session.

Code-Crash avatar Code-Crash commented on April 27, 2024

@unlucio , Yes, I tried that too, but I was getting CORS issue, and I have enabled the CORS on the server side also all the required headers, not sure what I was doing wrong.

before posting the query over here, I already did Google and Stack Overflow and tried a bunch of approaches, but no luck.

I didn't had much time, so I switch back to my own approach, passing the session token in headers from local storage and validating the same in middleware.

Thanks for the help.

from cookie-session.

Code-Crash avatar Code-Crash commented on April 27, 2024

@ahmedyounes Thanks for the hint, maybe I will try it once and will post here if the solutions work.

Thanks again! 👍

from cookie-session.

HazratAliii avatar HazratAliii commented on April 27, 2024

Did you solve it? I'm having same issue

from cookie-session.

Code-Crash avatar Code-Crash commented on April 27, 2024

@HazratAliii Yes, I was able to solve the issue, when we are talking about setting and getting the cookie, cors play an important role, please see if you are adding all the required details properly, as of now I'm not aware about your setup but if your server setup is in node with express, please see the below sample code:

/**
 * This method will help to set the cookie in response
 * @param {HttpResponseObject} res This is http response object on which we will apply the cookie
 * @param {string} token token to be applied on cookie
 * @param {string} domain for which domain we want to set the cookie
 */
const SetAccessTokenCookieInResponse = (res, token, domain) => {
  // Set the cookie in the response object
  logger.info('SetAccessTokenCookieInResponse - domain: ' + domain);
  const options = {
    maxAge: process.env.AUTH_SECRET_TOKEN_LIFE * 1000, // AUTH_SECRET_TOKEN_LIFE is in seconds, convert seconds to ms
    httpOnly: true,
    path: '/',
    secure: (process.env.NODE_LOCAL_ENV && process.env.NODE_LOCAL_ENV === 'local') ? false : true, // NOTE: while development on local, we need to pass secure:false and for any other env, it should be true
    domain: (process.env.NODE_LOCAL_ENV && process.env.NODE_LOCAL_ENV === 'local') ? 'localhost' : (process.env.AUTH_COOKIE_DOMAIN || domain), // domain name should be same, we can also use sub domain which is set in config
  };

  if (!process.env.NODE_LOCAL_ENV || process.env.NODE_LOCAL_ENV !== 'local') {
    options.sameSite = 'none';
  }

  res.cookie('your-cookie-name', token, options);
};
  
  

Also, make sure your headers are properly set as per CORS policy.

from cookie-session.

HazratAliii avatar HazratAliii commented on April 27, 2024

from cookie-session.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.