I upgraded from angular 1.2 (original code) more recently to 1.3 (which broke the cookies) to 1.4 as of today ($cookieStore is now deprecated infavor of $cookies)
I added a line $cookies.putObject('user', user);
but it isn't saved to cookies (i verified in chrome resources tab)
/**
* Authenticate user
*
* @param {Object} user - login info
* @param {Function} callback - optional
* @return {Promise}
*/
login: function (user, callback) {
var cb = callback || angular.noop;
return Session.save({
email: user.email,
password: user.password
}, function (user) {
$rootScope.currentUser = user;
$cookies.putObject('user', user); //does not save
return cb();
}, function (err) {
return cb(err);
}).$promise;
},
I put a breakpoint right after the $cookies.putObject
and I get undefined
when I try $cookies.getObject('user')
in chrome console.
This is an issue because now whenever I refresh the page, I lose the logged in user. The Auth.js
service has this line up front:
// Get currentUser from cookie
$rootScope.currentUser = $cookies.getObject('user') || null;