how to use sessions in express, couchDB, and node.js

后端 未结 4 397
你的背包
你的背包 2020-12-24 07:38

so I basically want to use sessions to store the users name and check to see if the user logged in or not. If not, the page will redirect to the login page.

I am usi

4条回答
  •  攒了一身酷
    2020-12-24 08:02

    I had same issue of getting undefined for session variable which I knew was set ok.

    In my case it turned out to be caused by cross origin request, I had forgotten the withCredentials header on the request.

    So for example in my client side Angular app I needed to do this:

    var config = { withCredentials: true };
    return $http.get(appConfig.apiUrl + '/orders', config);
    

    and in Express this:

    res.header('Access-Control-Allow-Credentials', true);
    

提交回复
热议问题