Search code examples
node.jsangularjsexpressangular-cookies

angularjs $cookieStore SyntaxError: JSON.parse: unexpected character


Have you got any ideas why I get an error

SyntaxError: JSON.parse: unexpected character

on this code

console.log($cookieStore.get('XSRF-TOKEN'));

the cookie value is

kscJcqrDYSMdZtBleuq8yUrB

?

UPDATE NODE CODE

var currentSession = req.session.passport;
var user = currentSession.user;
res.cookie('USER',JSON.stringify(user) , { maxAge: 900000, httpOnly: false});

Solution

  • $cookieStore is serialized session storage. It gives you error because value of cookie are not serialized.

    You need $cookies for your value.