ChanX
ChanX

Reputation: 372

Javascript not reading cookies set by Laravel

Javascript not reading cookies set by Laravel in the same domain and returning undefined. It's only reading the XSRF-Token but not any other cookies whether be it encrypted or unencrypted.

The URL is: http://localhost:8000/myaccount

and here is the cookie screenshot

enter image description here

I'm using JS Cookie library .. It's not reading either using document.cookie or Cookies.get('user_id') only the XSRF-TOKEN is reading.

Upvotes: 0

Views: 2059

Answers (2)

Finwe
Finwe

Reputation: 6725

The cookie is HttpOnly, therefore cannot be read by Javascript. You have to set the cookie as $httpOnly = false

See the last parameter of CookieJar::make method - which is mirrored in facade Cookie::make method.

Upvotes: 1

mtb
mtb

Reputation: 230

Cookie user-id has http-only flag set to true. It is not therefore accessible by javascript.

Try and set http-only flag to false.

edit: check this other SO answer it might get you started

Upvotes: 1

Related Questions