में सत्र बनाए रखने के लिए मैं उपयोग कर रहा हूँ पासपोर्ट जे एस, एक्सप्रेस और नेवला एक API बनाने के लिए विफल रहता है। जब मैं इसे उसी डोमेन में परीक्षण करता हूं तो यह सत्र बनाए रखता है और ठीक काम करता है। लेकिन क्रॉस डोमेन में यह विफल रहता है। कोई भी संकेत मैं उसी कॉन्फ़िगरेशन का उपयोग कर क्रॉस डोमेन में सत्र कैसे बनाए रख सकता हूं। निम्नलिखित कोडपासपोर्ट js क्रॉस-डोमेन
allowCrossDomain = function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
res.header("Access-Control-Allow-Headers", req.headers["access-control-request-headers"]);
// res.header("Access-Control-Allow-Credentials", "true");
if ("OPTIONS" == req.method) {
res.send(200);
} else {
next();
}
//allow all crossDomain request
app.use(allowCrossDomain);
//session handling
app.use(express.cookieParser("gallery"));
app.use(express.session());
app.use(passport.initialize());
app.use(passport.session());
app.use(function(req, res, next) {
// check if client sent cookie
var cookie = req.cookies.cokkieName;
if (cookie === undefined) {
//set up cookie here by a random number
});
}
next(); // <-- important!
});
passport.use(new LocalStrategy({
usernameField: "email"
},
function(email, password, done) {
User.authenticate(email, password, function(err, reply) {
//authenticate user and call the callback
return done(err, false);
});
}));
passport.serializeUser(function(user, done) {
return done(null, user._id);
});
passport.deserializeUser(function(id, done) {
//find user via id and return the user details
return done(null, user._id);
});
app.post("/login", function(req, res, next) {
passport.authenticate("local",
function(err, data, info) {
//custom callback
user.getProfile(req, res, next, err, data, info);
})(req, res, next);
});
साथ अपने मुख्य मॉड्यूल से इसे कहते @ कुंडू_ क्या आपको समाधान मिला? –