I have a problem trying to create an APIRest with express.
Currently, I have register and login working correctly using MongoDB and passport, the problem is that when I login, I need the API to understand that the user is still logged in, so I'm using:
//Session
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: true,
cookie: { httpOnly: false, maxAge: null, secure: false },
store: new MongoStore({
url: configDB.url,
collection: 'sessions'
})
}));
To check if the user is authenticated, i'm using:
//Confirm Login status
app.get('/api/loggedin', function (req, res) {
return res.send(req.isAuthenticated() ? req.user : 'Not Logged!');
});
With the function:
function IsAuthenticated(req, res, next) {
if (req.isAuthenticated()) {
next();
} else {
next(res.send('Sorry!'));
}
}
Using Postman, it works just fine, I can see te cookie "connect.sid". But when I login from angularjs using this endpoint, the cookie is not beeing set, and basically, it does not work, returns "Not Logged!".
PS: I'm using ionic as my framework. My node API server is under Azure webapp.
Any question lt me know guys, thanks so far!