Comments (10)
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.
Hey @Code-Crash, might this be of help?
from cookie-session.
@cloudhary , Thanks for the help. let me test it and will get back to you in some time.
from cookie-session.
@Code-Crash you are right , just noticed the same and its working with postman ... trying what @cloudhary introduced
from cookie-session.
@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.
@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.
@ahmedyounes Thanks for the hint, maybe I will try it once and will post here if the solutions work.
Thanks again! 👍
from cookie-session.
Did you solve it? I'm having same issue
from cookie-session.
@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.
from cookie-session.
Related Issues (20)
- What am I doing wrong? [question] HOT 1
- Clearing session does not remove cookies HOT 8
- Generating unique session.sig after logout/login HOT 3
- Use cookie-session as non middleware HOT 2
- Document: Ambiguity in Signature Documentation HOT 4
- sameSite no longer defaults to 'None' when undefined HOT 4
- session cookie value is exceedingly long and fails Set-Cookie with invalid syntax HOT 2
- secureProxy option to be able to use with non-Express servers behind SSL proxy HOT 1
- Suggestion: a custom name instead of req.session HOT 2
- Update dependency from [email protected] to [email protected] HOT 3
- Is there a risk when someone modifies the userId in the cookie? HOT 2
- Session cookie not sent over from server when using Firefox HOT 4
- Problem using with passport 0.6.0: session.regenerate is not a function HOT 7
- flag Priority=High
- encrypt cookies
- The link to a list of browser cookie limits is dead
- Larger cookies with compression
- cookie options not being set
- Secure flag is ignored
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cookie-session.