使用快速会话和angularjs

时间:2016-12-27 23:42:24

标签: angularjs node.js session cookies ionic-framework

尝试使用express创建APIRest时遇到问题。

目前,我使用MongoDB和护照注册并登录正常,问题是当我登录时,我需要API来了解用户仍然登录,所以我正在使用:

//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'
    })
}));

要检查用户是否已通过身份验证,我正在使用:

//Confirm Login status
app.get('/api/loggedin', function (req, res) {
    return res.send(req.isAuthenticated() ? req.user : 'Not Logged!');
});

使用功能:

function IsAuthenticated(req, res, next) {
    if (req.isAuthenticated()) {
        next();
    } else {
        next(res.send('Sorry!'));
    }
}

使用Postman,它工作正常,我可以看到te cookie“connect.sid”。但是当我使用此端点从angularjs登录时,cookie没有设置,基本上,它不起作用,返回“Not Logged!”。

PS:我正在使用离子作为我的框架。我的节点API服务器位于Azure webapp下。

任何问题,我都知道伙计们,感谢到目前为止!

0 个答案:

没有答案