Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request Object Lost context #21

Open
akash880 opened this issue Mar 14, 2018 · 0 comments
Open

Request Object Lost context #21

akash880 opened this issue Mar 14, 2018 · 0 comments

Comments

@akash880
Copy link

Hi,
I am using facebook strategy with my Node-express app,

Sometimes if multiple users log in simultaneously, request object lost context and we get the wrong user details.

example of route
app.get('/', isLoggedIncheck, checkIfFromFacebook, function(req, res) {

     res.setHeader('x-auth-token1111', 'sfdsdf');
     res.header('x-auth-token1111' , 'sfdsdf' );
//    res.status(200).send(data.user);

     const data = {};
    data.spath =req.protocol + '://' + req.hostname +':'+port+'/';
    
    if (req.user != undefined) {



        data.user = req.user;

            

        data.user.token = jwt.sign({
                id: req.user.userid,
            },
            'secret'
        );

        res.cookie(req.user.username, JSON.stringify(data.user.token));
        res.cookie(req.user.userid, JSON.stringify(data.user.token));

    } else {
        
        
        data.user = '';

    }
    data.server = req.hostname;
    data.min = min;
    data.id = generateId();
    data.ver = version;
    data.port = port;
    data.path = '/explore';
    data.page = 'explore';
    data.curl =req.protocol + '://' + req.hostname;
    data.title = 'Woovly | Bucket List | Discover, Connect and Accomplish';
    data.contrl = 'explore';
    data.meta = {};
    data.meta.storyL = {};
    data.meta.storyL.name = 'home';
    data.meta.storyL.title = '';
    data.uuid = "";
    data.is_set = '';
    var htmlFile = '';
    htmlFile = 'explore.html';
    data.utyp = '';
    res.render(htmlFile, { dt: data });
});

app.get("/getFeatured", checkIfFromFacebook, function(req, res) {

     const data = {};
    data.spath =req.protocol + '://' + req.hostname +':'+port+'/';
    
    if (req.user != undefined) {



        data.user = req.user;



        data.user.token = jwt.sign({
                id: req.user.userid,
            },
            'secret'
        );

        res.cookie(req.user.username, JSON.stringify(data.user.token));
        res.cookie(req.user.userid, JSON.stringify(data.user.token));

    } else {
        
        
        data.user = '';

    }
    console.log(req.headers['x-key']);
    data.server = req.hostname;
    data.min = min;
    data.ver = version;
    data.port = port;
    data.path = "getFeatures";
    data.page = "getFeatures";
    data.curl =req.protocol + '://' + req.hostname+'/getFeatured';
    data.title = "getFeatures";
    data.contrl = "getFeatured";

    data.is_set = "";
    data.user_name = "";
    data.uuid = "";
    data.utyp = "";
    data.meta = {};

    res.render("getFeatures.html", { dt: data });
});

app.get('/auth/facebook', (req, res, next) => {
req.session.redirect = req.query.location;
passport.authenticate('facebook', { scope: ['user_friends', 'user_likes', 'email', 'user_birthday', 'user_location'] })(req, res, next)
});

app.get(
    '/auth/facebook/callback', (req, res, next) => {
        console.log("****************");
        console.log(req.session.redirect);
        if (req.session.redirect == undefined || req.session.redirect == 'undefined')
            req.session.redirect = '/';
        passport.authenticate('facebook', {
            successRedirect: req.session.redirect,
            failureRedirect: '/',
        })(req, res, next)

    });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant