mindparse
mindparse

Reputation: 7265

AngularJS - Unable to read a cookie sent back from Express server

I have an angular app hosted with Express, and am using the express-session plugin to generate session cookies.

So on login, I see the session cookie gets generated and sent back to my angular app in the response.

I'm now trying to check for the presence of the cookie in my angular code, but if I try reading document.cookie I just get an empty sting back, yet I can see the cookie is set looking in my Chrome debugger tools.

I tried using $cookies (I am using angular 1.3 right now), but even that returns undefined if I try $cookies['mycookiename']

Can anyone give me some clues please? Thanks

Upvotes: 0

Views: 215

Answers (2)

Max Harney
Max Harney

Reputation: 26

Is your cookie marked HTTP only? If so, the cookie will be unavailable to the JavaScript.

Upvotes: 1

Amonn
Amonn

Reputation: 84

This looks like a CORS problem. You need to let the browser know what headers to pass to JavaScript. Configuring Access-Control-Allow-Headers on the server is what you should be looking at.

Upvotes: 0

Related Questions