Safari isn't saving cookies, but Chrome is

后端 未结 2 775
面向向阳花
面向向阳花 2020-12-18 14:49

UPDATE: It\'s worth mentioning, my website is being loaded via an iframe.

Here\'s my cookieSession in my app.js:

app.use(cookieParser());

app.use(         


        
相关标签:
2条回答
  • 2020-12-18 15:23

    If you page is loaded in an iframe, the end user may choose to block Third Party Cookies which would prevent your website from writing the cookie.

    See Safari Privacy Settings. for more info

    Did you try to see if the cookie worked when the page was visited directly instead of an iframe?

    0 讨论(0)
  • 2020-12-18 15:31

    It looks like you hit a Safari bug here (https://bugs.webkit.org/show_bug.cgi?id=3512); You are redirecting any visiting browser to /dashboard while setting the cookie at the same time, and Safari is ignoring the Set-Cookie header when encountering the 302( or 301 I thing so) HTTP status. In this case you need keep user token in a variable an put it to /dashboard controller then recheck and store user token in req.session.

    • Updated: Post your token (genereted by login controller) to dashboard controller

    app.post('/login', function(req, res) {
        Parse.User.logIn(req.body.username, req.body.password).then(function(user) {
            res.redirect('/dashboard?token=' + user.getSessionToken() + '&user=' + user);
        }, function(error) {
            console.log(error)
            req.session = null;
            res.render('login');
        });
    
    });
    
    
    app.post('/dashboard', function(req, res) {
        if (req.query.user && req.query.token) {
            // save for first time
            req.session.user = req.query.user;
            req.session.token = req.query.user;
        }
      // check token in session before go
    
    });

    0 讨论(0)
提交回复
热议问题