4

I have an application using Angular and Node (Nest JS) , in the server side i'm using express-session. In my middleware i'm adding the logged in user to the session:

req.session.user = user;

When the user tries to login using an Iphone he is not able to login. after debbuging the issue I found that each request has a different sessionId. I can see that after I inlitialze the user in the session it works fine, but than the next request is empty (no user object) and has a new id.

This issue occures only in IOS.

I did try to change the express-sessions options: maxAge, httpOnly, resave, saveUninitialized and nothing worked.

These are my express definitions:

app.then(instance => {
    instance.use(compress({
        filter: function ( req, res ) {
            return (/json|text|javascript|css|font|svg/).test(res.getHeader('Content-Type'));
        },
level: 9
}))
if ( _.has(config, 'log.format') ) {
    instance.use(morgan(':method :url :status :res[content-length] - :response-time ms', Logger.getMorganOptions()));
}
instance.use(bodyParser.json());
instance.use(bodyParser.urlencoded({extended: true}));

instance.use(cookieParser(config.sessionSecret));

var MemoryStore = require('memorystore')(session);
instance.use(session({
    store: new MemoryStore({
        checkPeriod: 86400000 // prune expired entries every 24h
    }),
    saveUninitialized: true,
    resave: true,
    secret: config.sessionSecret,
    cookie: {
        maxAge: null,
        httpOnly: false,
    },
    name: config.sessionKey,
}));

var corsOptions = {
    origin: function ( origin, callback ) {
        var isWhitelisted = originsWhitelist.indexOf(origin) !== -1;
        callback(null, isWhitelisted);
    },
    credentials: true,
};
instance.use(cors(corsOptions));

instance.listen(3000, () =>
    console.log('Application is listening on port 3000')
)
});
Shahar Shmaram
  • 233
  • 1
  • 4
  • 10
  • 4
    Just stumbled upon the same issue. Have you solved it by any chance? – scarably Nov 14 '18 at 23:14
  • 1
    Exact same issue, any joy? – TommyBs Nov 27 '18 at 07:49
  • 1
    My issue is little bit similar and not exactly the same. iOS client is working as expected (request.session.user is available in every request after login), but when iOS app is closed and re-opened and hit the server, then server is observed not to have 'request.session.user' object, also session id is changed. But this happens only in app close + re-open case. Any suggestions regarding this ? – Shiv Dec 27 '18 at 11:10
  • 1
    same problem in 2020. iphone 6 – titoih May 05 '20 at 08:51
  • same, Iphone 6s, any solutions? – ezg Sep 03 '20 at 03:10
  • Pls is there any solution so far. Pls I need help – Paulliano Sep 29 '22 at 23:26

0 Answers0